我有下面的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=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%>
<%@page import="javax.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="javax.naming.*"%>
<%@page import="java.io.*" %>
<html>
<head>
<%!
class LinkedProperties extends Properties {
private final LinkedHashSet<Object> keys = new LinkedHashSet<Object>();
public Enumeration<Object> keys() {
return Collections.<Object>enumeration(keys);
}
public Object put(Object key, Object value) {
keys.add(key);
return super.put(key, value);
}
}
public String getData(ResultSet rs, String tableName) throws Exception {
String ret ="<div class='tname'>"+tableName+"</div>";
ret+="<table border=1>";
ret+="<tr>";
ResultSetMetaData md = rs.getMetaData() ;
for( int i = 1; i <= md.getColumnCount(); i++ ) {
if(md.getColumnLabel(i).equals("UPDATE_DATE") || md.getColumnLabel(i).equals("Update Date")) {
ret = ret + "<th class='upd'>"+ md.getColumnLabel(i) + "</th>";
} else if(md.getColumnLabel(i).equals("ASSIGNED_TO") || md.getColumnLabel(i).equals("Assigned To")) {
ret = ret + "<th class='upd'>"+ md.getColumnLabel(i) + "</th>";
} else if(md.getColumnLabel(i).equals("UPDATED_BY") || md.getColumnLabel(i).equals("Updated By")) {
ret = ret + "<th class='upd'>"+ md.getColumnLabel(i) + "</th>";
} else {
ret = ret + "<th>"+ md.getColumnLabel(i) + "</th>";
}
}
ret+="</tr>";
int cnt = 0;
while( rs.next() )
{
cnt++;
ret+="<tr>";
for( int i = 1; i <= md.getColumnCount(); i++ )
{
if(rs.getString(i) == null) {
ret = ret + "<td> </td>";
} else {
ret = ret + "<td>"+ rs.getString(i) + "</td>";
}
}
ret+="</tr>";
}
if(cnt == 0) return "";
ret+="</table><BR/>";
return ret;
}
%>
<%!
public String execute(Connection conn, String str, String tableType) throws Exception {
Statement stmt = null;
ResultSet rset = null;
try {
stmt = conn.createStatement();
rset = stmt.executeQuery(str);
return getData(rset, tableType);
} catch (Exception exp) {
throw exp;
} finally {
try { rset.close(); } catch (Exception ignore) {}
try { stmt.close(); } catch (Exception ignore) {}
}
}
%>
<%
String key, val;
String sql = "";
String ret = "";
Connection conn = null;
try {
String typ = "role";//request.getParameter("t");
if(typ==null) throw new Exception("Type is blank");
if(!typ.equals("role") && !typ.equals("produit")) {
throw new Exception("Invalid Type");
}
InputStream stream = application.getResourceAsStream("/tasksdisplay.properties");
LinkedProperties props = new LinkedProperties();
props.load(stream);
LinkedHashMap<String, String> mapSQL = new LinkedHashMap<String, String>();
String dbname = "mdmtrg01-CMX_ORS";//request.getParameter("d");
if(dbname == null) {
dbname = "mdmtrg01-CMX_ORS";
}
String dbJNDIName = "java:jdbc/siperian-mdmtrg01-cmx_ors-ds";//System.getProperty(dbname);
if(dbJNDIName == null) {
throw new Exception("Invalid database name. Must set dbname in JBoss startup");
}
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "iiop://mdma302p.corpads.local:30305");
Context initialContext = new InitialContext(env);
Context aContext = new InitialContext(env);
DataSource aDataSource = (DataSource)aContext.lookup("java:jdbc/siperian-mdmtrg01-cmx_ors-ds");
//DataSource aDataSource = (DataSource)aContext.lookup(dbJNDIName);
conn = (Connection)(aDataSource.getConnection());
for (Map.Entry<String,String> entry : mapSQL.entrySet()) {
key = entry.getKey();
sql = entry.getValue();
ret = execute(conn, sql, key);
%>
<%=ret%>
<%
}
%>
<%
} catch (Exception exp) {
exp.printStackTrace();
String err = exp.toString();
err += "<BR/>sql##E:"+sql;
%>
Error:<%=err%>
<%
} finally {
try { conn.close(); } catch (Exception ignore) {}
}
%>
<style>
.tname {
color: red;
font-size: 16px;
font-weight:bold;
}
table{
font-family: Verdana;
font-size: 12px;
font-weight: normal;
text-align: center;
}
table th {
color: #225F8E;
}
table td {
background-color: #DBFCF5;
}
a {
color: blue;
}
.upd {
background-color: yellow;
}
</style>
</head>
</html>
我正在使用JDK1.7。添加 2 个 JARS 后,我得到以下错误 Error:javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set。可能的原因是用户在 JNDI 上下文方法调用中指定了 java: URL 名称,但未在 J2EE 客户端或服务器环境中运行。
在端口 8080 上启动预览服务器
模块:customTabFromKb_1 (/customTabFromKb_1) 代理 (/proxy)
NMSV0307E: 使用了 java: URL 名称,但未将命名配置为处理 java: URL 名称。可能的原因是用户在尝试在非 J2EE 客户端或服务器环境中指定 java: URL 名称时出错。抛出配置异常。javax.naming.ConfigurationException:java 的名称空间访问器:尚未设置名称空间。可能的原因是用户在 JNDI 上下文方法调用中指定了 java: URL 名称,但未在 J2EE 客户端或服务器环境中运行。在 com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:109) 在 com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:85) 在 javax.naming.spi.NamingManager .getURLContext(NamingManager.java:660) 在 javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java: run(SocketConnector.java:228) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) NMSV0307E: 使用了 java: URL 名称,但命名未配置为处理 java: URL 名称。可能的原因是用户在尝试在非 J2EE 客户端或服务器环境中指定 java: URL 名称时出错。抛出配置异常。javax.naming.ConfigurationException:java 的名称空间访问器:尚未设置名称空间。可能的原因是用户在 JNDI 上下文方法调用中指定了 java: URL 名称,但未在 J2EE 客户端或服务器环境中运行。在 com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:109) 在 com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:85) 在 javax.naming.spi.NamingManager .
请在这方面帮助我!