ejbsimpappservlet.jsp
来自「weblogic应用全实例」· JSP 代码 · 共 167 行
JSP
167 行
<%
/*
*这个JSP文件演示一个WebLogic服务器怎样转换WebLogic Enterprise
*/
%>
<html>
<head>
<title>Weblogic Enterprise Connectivity - Simpapp EJB Sample</title>
</head>
<body bgcolor=#8B129C>
<p><img src=images/BEA_Button_Final_web.gif align=right>
<h2>
<font color=#FFFFFF>
Weblogic Enterprise Connectivity - Simpapp EJB Sample
</font>
</h2>
<%//引入的其它类%>
<%@ page import="
javax.servlet.*,
javax.servlet.http.*,
java.io.*,
java.util.Properties,
javax.ejb.*,
javax.naming.*,
java.rmi.RemoteException,
java.util.*,
examples.wlec.ejb.simpapp.*
"%>
<%
// 从主接口获取远程对象,并调用toLower方法和toUpper方法,并把结果编辑成jsp页面,返回到客户端
final String defaultCase = "UPPER";
final String defaultString = "It Works";
ConverterResult result;
// 读入输入的数据
String mixed = (String) request.getParameter("InData");
String changeCase = (String) request.getParameter("ChangeCase");
String user = (String) request.getParameter("user");
String password = (String) request.getParameter("password");
if(user!=null && password!=null)
{
%>
<p><font color=#FFFFFF>"Note: Using the user: "<%= user %> "and password: "<%= password %></font>
<%
}
else {
%>
<p><font color=#FFFFFF>"Note: No user and password credentials"</font>
<%
}
// 如果没有参数,则使用缺省default字符串
if ((mixed == null) || (mixed.length() <= 0)) {
mixed = defaultString;
%>
<p><font color=#FFFFFF>"Note: Using the default data: "<%= mixed %></font>
<%
}
// 缺省转换成大写
if ((changeCase == null) || (changeCase.length() <= 0)) {
changeCase = defaultCase;
%>
<p><font color=#FFFFFF>"Note: Using the default action: "<%= changeCase %></font>
<%
}
try {
// 创建converter对象
Context ctx = getInitialContext(user, password);
ConverterHome converterH = (ConverterHome) ctx.lookup("simpapp.ConverterHome");
Converter converter = converterH.create();
try {
if (changeCase.equals(defaultCase)) {
// 大写
result = converter.toUpper(mixed);
}
else
{
// 小写
result = converter.toLower(mixed);
}
%>
<p><font color=#FFFFFF>"Output String: "<%= result.outData %></font>
<%
}
catch (ProcessingErrorException pe) {
//异常处理
out.print("Processing Error: " + pe);
return;
}
catch (Exception e) {
//其它异常处理
out.print(":::::::::::::: Error :::::::::::::::::");
return;
}
if (converter != null) {
try {
// 清除converter
converter.remove();
}
catch (Exception e) {
//异常处理
out.print("Error removing converter ");
return;
}
}
}
catch (Exception e) {
//其它异常处理
out.print(":::::::::::::: Error :::::::::::::::::");
return;
}
%>
<%!
//获取初始化上下文
//返回 Context
//异常 java.lang.Exception
static public Context getInitialContext(String user, String password)
throws Exception {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
if (user != null) {
p.put(Context.SECURITY_PRINCIPAL, user);
if (password == null)
password = "";
p.put(Context.SECURITY_CREDENTIALS, password);
}
return new InitialContext(p);
}
%>
</font>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?