当前位置:软件学习 > 其它软件 >>

請教wsad7中jndi的設置

我在wsad7中如下設置,但是在jsp中測試,始終不能取得連接:
1.web.xml代碼如下:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
HR</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<resource-ref id="ResourceRef_1198572921825">
<description>jndi_dudb1</description>
<res-ref-name>jdbc/dudb1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>

2.jsp中代碼如下:


 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=BIG5"
pageEncoding="BIG5"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<%!
    final String JNDI ="java:comp/env/jdbc/dudb1";
%>

<body bgcolor="white">
<h1>Welcome to this page!!!</h1>
<%
   Connection conn =null;
   try
   {
   Context ctx = new InitialContext();
   DataSource ds =(DataSource)ctx.lookup(JNDI);
   conn = ds.getConnection();
   }
   catch(Exception e)
   {
   System.out.println(e);
   }
%>
<%=conn%>
</body>
</html>


--------------------编程问答-------------------- 在WS的控制台(http://localhost:9060/ibm/console,端口号根据你机器的具体情况了)中做如下操作:
首先在JDBC的配置中选好合适的数据库和创建的连接池类型。并且指定数据库的驱动路径。
在JAAS - J2C 把DB相关的信息写好。DB Name ,User ,Psw。
在WS61中,创建了DataSource的时候的JNDI名要设置为你现在写的这个jdbc/dudb1 ,
在组件的认证和容器认证都要选择你刚才创建的那个JAAS - J2C认证。
然后点  Test Connection  ,然后祈祷,如果能正常连接,才说明服务器端的数据源做好了,不能连接的话,网页里面就不用想了。
会出错的原因太多了,出错最多的地方是数据库的驱动部分。


希望对你能有些帮助,呵呵! --------------------编程问答-------------------- 按楼上的操作应该就OK了,
要是还不行,查一下WEB-INF下的ibm-web-bnd.xmi文件 --------------------编程问答-------------------- 十分感謝你們,
我的email是:shlaistar@gmail.com.
希望能成為好朋友. --------------------编程问答-------------------- 謝謝,終於成功了.
剛接觸wsad,
以後請多指教! --------------------编程问答-------------------- 怎么解决的? --------------------编程问答-------------------- 打開admin console --> 資源選項 -->jdbc
設置數據庫的各參數就完成了.

也就是按2樓的朋友說的那樣做 --------------------编程问答-------------------- 不明LZ在说什么 --------------------编程问答-------------------- 等待牛人来答. --------------------编程问答-------------------- 这个简单啊,网上搜一下就得到答案了. --------------------编程问答--------------------
补充:企业软件 ,  WebSphere
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,