免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2769 | 回复: 0
打印 上一主题 下一主题

[WebLogic] Weblogic下使用jsp查询的Entity Bean [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-15 00:09 |只看该作者 |倒序浏览
  1. <%@ page contentType="text/html; charset=GBK" %>
  2. <%@ page import="baisha.*"%>
  3. <%@ page import="javax.naming.*"%>
  4. <%!
  5.   private javax.naming.Context getInitialContext() throws Exception {
  6.     String url = "t3://localhost:7001";
  7.     String user = null;
  8.     String password = null;
  9.     Properties properties = null;
  10.     try {
  11.       properties = new Properties();
  12.       properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  13.       properties.put(Context.PROVIDER_URL, url);
  14.       if (user != null) {
  15.         properties.put(Context.SECURITY_PRINCIPAL, user);
  16.         properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
  17.       }

  18.       return new InitialContext(properties);
  19.     }
  20.     catch(Exception e) {
  21.       System.out.println(e.getMessage());
  22.       return null;
  23.     }
  24.   }

  25. %>
  26. <html>
  27. <head>
  28. <title>
  29. Jsp1
  30. </title>
  31. </head>
  32. <body>
  33. <%
  34. //Properties env =new Properties();
  35. // env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
  36. // env.put(Context.INITIAL_CONTEXT_FACTORY,"t3://localhost:7001");
  37. //Context ctx = new InitialContext(env);
  38. String str_id=null;
  39. str_id =request.getParameter("id");
  40. javax.naming.Context ctx = new javax.naming.InitialContext();
  41. Object ref = ctx.lookup("Province");
  42. baisha.ProvinceHome provHome =null;
  43. baisha.Province prov = null;
  44. provHome = (baisha.ProvinceHome)javax.rmi.PortableRemoteObject.narrow(ref,ProvinceHome.class);
  45. if (provHome==null) {
  46.    out.println("provHome is null");
  47. }
  48. else
  49.     {
  50.     if (str_id==null){
  51.    
  52.     }
  53.     else{
  54.       try{
  55.         prov = provHome.findByPrimaryKey(new Integer(str_id));
  56.         out.println(prov.getProvinceName());
  57.         }
  58.       catch(Exception e){
  59.        out.println("ID 不存在!");
  60.       }  
  61.     }
  62.     }
  63.   
  64.      
  65. %>
  66. <h1>
  67. JBuilder Generated JSP
  68. </h1>
  69. <form method="post" action="query.jsp">
  70. <br>Enter new value   :  <input name="id"  type="text"><br>
  71. <br><br>
  72. <input type="submit" name="Submit" value="Submit">
  73. <input type="reset" value="Reset">
  74. <br>

  75. </form>
  76. </body>
  77. </html>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP