当前位置:编程学习 > JSP >>

Weblogic下使用jsp查询的Entity Bean

答案:<%@ 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>

上一个:jsp调用Entity Bean的例子
下一个:Java数据对象(JDO)的应用(转)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,