Weblogic下使用jsp查询的Entity Bean
发表于:2007-07-01来源:作者:点击数:
标签:
%@ page contentType=text/html; charset=GBK % %@ page import=baisha.*% %@ page import= java x.naming.*% %! private javax.naming.Context getInitialContext() throws Exception { String url = t3://localhost:7001; String user = null; String passw
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="baisha.*"%>
<%@ page import="
javax.naming.*"%>
<%!
private javax.naming.Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "
weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
return new InitialContext(properties);
}
catch(Exception e) {
System.out.println(e.getMessage());
return null;
}
}
%>
<html>
<head>
<title>
Jsp1
</title>
</head>
<body>
<%
//Properties env =new Properties();
// env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
// env.put(Context.INITIAL_CONTEXT_FACTORY,"t3://localhost:7001");
//Context ctx = new InitialContext(env);
String str_id=null;
str_id =request.getParameter("id");
javax.naming.Context ctx = new javax.naming.InitialContext();
Object ref = ctx.lookup("Province");
baisha.ProvinceHome provHome =null;
baisha.Province prov = null;
provHome = (baisha.ProvinceHome)javax.rmi.PortableRemoteObject.narrow(ref,ProvinceHome.class);
if (provHome==null) {
out.println("provHome is null");
}
else
{
if (str_id==null){
}
else{
try{
prov = provHome.findByPrimaryKey(new Integer(str_id));
out.println(prov.getProvinceName());
}
catch(Exception e){
out.println("ID 不存在!");
}
}
}
%>
<h1>
JBuilder Generated JSP
</h1>
<form method="post" action="query.jsp">
<br>Enter new value : <input name="id" type="text"><br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
</form>
</body>
</html>
原文转自:http://www.ltesting.net