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>
复制代码
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论