jsp调用Entity Bean的例子
发表于:2007-07-04来源:作者:点击数:
标签:
%@ 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 passwor
<%@ 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;
String str_name=null;
str_id =request.getParameter("id");
str_name = request.getParameter("name");
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.create(new Integer(str_id),str_name);
out.println(prov.getProvinceName());
}
catch(Exception e){
out.println("新增不成功!");
}
}
}
%>
<h1>
新增信息
</h1>
<form method="post" action="add.jsp">
<br>Enter new value : <input name="id" type="text"><br>
<br><br>
<input name="name" type="text">
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
</form>
</body>
</html>
原文转自:http://www.ltesting.net