protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
try {
Context initialContext = new InitialContext();
String a = "zyy: aaaaaaaaaaaaaa10";
initialContext.bind("some/where/over/there", a);
LinkRef linkref = new LinkRef("some/where");
initialContext.bind("here", linkref);
PrintWriter out = response.getWriter();
Thread.currentThread().setContextClassLoader(oldCL);
out.println("test lookupLink");
try {
LinkRef value1 = (LinkRef) initialContext.lookupLink("here");
out.println("here value 111111111: " + value1);
if (value1 != null)
out.println("here value 2222222222222: " + value1.getLinkName());
LinkRef value = (LinkRef) initialContext
.lookupLink("here/over/there");
out.println("here value 3333333333333: " + value);
if (value != null)
out.println("zyy value: " + value.getLinkName());
} catch (NamingException e) {
//out.println("zyy not found!");
e.printStackTrace();
}
} catch (NamingException e) {
e.printStackTrace();
} finally {
Context initialContext;
try {
initialContext = new InitialContext();
initialContext.unbind("some/where/over/there");
initialContext.unbind("here");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
以上Servlet输出结果是什么?在所有jee应用服务器上都出错.那么lookupLink到底如何用,LinkRef到底如何用?谁能给个例子?
HttpServletResponse response) throws ServletException, IOException {
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
try {
Context initialContext = new InitialContext();
String a = "zyy: aaaaaaaaaaaaaa10";
initialContext.bind("some/where/over/there", a);
LinkRef linkref = new LinkRef("some/where");
initialContext.bind("here", linkref);
PrintWriter out = response.getWriter();
Thread.currentThread().setContextClassLoader(oldCL);
out.println("test lookupLink");
try {
LinkRef value1 = (LinkRef) initialContext.lookupLink("here");
out.println("here value 111111111: " + value1);
if (value1 != null)
out.println("here value 2222222222222: " + value1.getLinkName());
LinkRef value = (LinkRef) initialContext
.lookupLink("here/over/there");
out.println("here value 3333333333333: " + value);
if (value != null)
out.println("zyy value: " + value.getLinkName());
} catch (NamingException e) {
//out.println("zyy not found!");
e.printStackTrace();
}
} catch (NamingException e) {
e.printStackTrace();
} finally {
Context initialContext;
try {
initialContext = new InitialContext();
initialContext.unbind("some/where/over/there");
initialContext.unbind("here");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
以上Servlet输出结果是什么?在所有jee应用服务器上都出错.那么lookupLink到底如何用,LinkRef到底如何用?谁能给个例子?
在 LinkRef value = (LinkRef) initialContext.lookupLink("here/over/there");出错
报over.there 无法解析Tomcat 直接是就是name not found 异常
13:49:22,796 INFO [STDOUT] test lookupLink
13:49:22,796 INFO [STDOUT] here value 111111111: Reference Class Name: javax.naming.LinkRef
Type: LinkAddress
Content: some/where
13:49:22,796 INFO [STDOUT] here value 2222222222222: some/where
13:49:22,796 INFO [STDOUT] here value 3333333333333: zyy: aaaaaaaaaaaaaa10
13:49:22,796 INFO [STDOUT] zyy value: zyy: aaaaaaaaaaaaaa10使用 lookupLink("here/over/there") 时:
13:49:22,796 INFO [STDOUT] test lookupLink
13:49:22,796 INFO [STDOUT] here value 111111111: Reference Class Name: javax.naming.LinkRef
Type: LinkAddress
Content: some/where
13:49:22,796 INFO [STDOUT] here value 2222222222222: some/where
13:49:22,796 INFO [STDOUT] here value 3333333333333: javax.naming.spi.ResolveResult@1cacbd9
13:49:22,796 INFO [STDOUT] zyy value: javax.naming.spi.ResolveResult@1cacbd9
try {
Context initialContext = new InitialContext();
String a = "zyy: aaaaaaaaaaaaaa10";
Context ctx = initialContext; try {
ctx = (Context) initialContext.lookup("some");
} catch (NameNotFoundException e) {
ctx = initialContext.createSubcontext("some");
} try {
ctx = (Context) initialContext.lookup("where");
} catch (NameNotFoundException e) {
ctx = initialContext.createSubcontext("where");
} try {
ctx = (Context) initialContext.lookup("over");
} catch (NameNotFoundException e) {
ctx = initialContext.createSubcontext("over");
} initialContext.bind("some/where/over/there", a);
LinkRef linkref = new LinkRef("some/where");
initialContext.bind("here", linkref); System.out.println("test lookupLink");
try {
LinkRef value1 = (LinkRef) initialContext.lookupLink("here");
System.out.println("here value 111111111: " + value1);
if (value1 != null)
System.out.println("here value 2222222222222: " + value1.getLinkName());
Object value = initialContext.lookup("here/over/there"); 或 lookupLink 都可工作,但 lookupLink 返回 javax.naming.spi.ResolveResult,返回的结果类型不同,原来的对象已经解析了。
System.out.println("here value 3333333333333: " + value);
if (value != null)
System.out.println("zyy value: " + value);
} catch (NamingException e) {
// out.println("zyy not found!");
e.printStackTrace();
}
} catch (NamingException e) {
e.printStackTrace();
} finally {
Context initialContext;
try {
initialContext = new InitialContext();
initialContext.unbind("some/where/over/there");
initialContext.unbind("here");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
13:51:45,203 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:771)
13:51:45,218 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:779)
13:51:45,218 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingS
erver.java:785)
13:51:45,265 ERROR [STDERR] at org.jnp.server.NamingServer.unbind(NamingServ
er.java:315)
13:51:45,265 ERROR [STDERR] at org.jnp.server.NamingServer.unbind(NamingServ
er.java:318)
13:51:45,265 ERROR [STDERR] at org.jnp.interfaces.NamingContext.unbind(Namin
gContext.java:871)
13:51:45,265 ERROR [STDERR] at org.jnp.interfaces.NamingContext.unbind(Namin
gContext.java:854)
13:51:45,265 ERROR [STDERR] at javax.naming.InitialContext.unbind(InitialCon
text.java:416)
13:51:45,265 ERROR [STDERR] at org.apache.jsp.TestJndi_jsp._jspService(TestJ
ndi_jsp.java:112)
13:51:45,265 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service
(HttpJspBase.java:70)
13:51:45,265 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:717)
13:51:45,265 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.s
ervice(JspServletWrapper.java:369)
13:51:45,265 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJ
spFile(JspServlet.java:322)
13:51:45,265 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(
JspServlet.java:249)
13:51:45,265 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:717)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:290)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:206)
13:51:45,265 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilte
r.doFilter(ReplyHeaderFilter.java:96)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:235)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:206)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve
.invoke(StandardWrapperValve.java:235)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve
.invoke(StandardContextValve.java:191)
13:51:45,265 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssocia
tionValve.invoke(SecurityAssociationValve.java:190)
13:51:45,265 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValv
e.invoke(JaccContextValve.java:92)
13:51:45,265 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContext
EstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
13:51:45,265 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContext
EstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.in
voke(StandardHostValve.java:127)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.i
nvoke(ErrorReportValve.java:102)
13:51:45,265 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnec
tionValve.invoke(CachedConnectionValve.java:158)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.
invoke(StandardEngineValve.java:109)
13:51:45,265 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.s
ervice(CoyoteAdapter.java:330)
13:51:45,265 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.proc
ess(Http11Processor.java:829)
13:51:45,265 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http1
1ConnectionHandler.process(Http11Protocol.java:598)
13:51:45,281 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker
.run(JIoEndpoint.java:447)
13:51:45,281 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
13:51:48,187 ERROR [STDERR] javax.naming.NameNotFoundException: where not bound
13:51:48,187 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:771)
13:51:48,187 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:779)
13:51:48,187 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingS
erver.java:785)
13:51:48,187 ERROR [STDERR] at org.jnp.server.NamingServer.bind(NamingServer
.java:161)
13:51:48,187 ERROR [STDERR] at org.jnp.server.NamingServer.bind(NamingServer
.java:167)
13:51:48,203 ERROR [STDERR] at org.jnp.interfaces.NamingContext.bind(NamingC
ontext.java:650)
13:51:48,203 ERROR [STDERR] at org.jnp.interfaces.NamingContext.bind(NamingC
ontext.java:611)
13:51:48,203 ERROR [STDERR] at javax.naming.InitialContext.bind(InitialConte
xt.java:400)
13:51:48,203 ERROR [STDERR] at org.apache.jsp.TestJndi_jsp._jspService(TestJ
ndi_jsp.java:88)
13:51:48,203 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service
(HttpJspBase.java:70)
13:51:48,203 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:717)
13:51:48,203 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.s
ervice(JspServletWrapper.java:369)
13:51:48,203 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJ
spFile(JspServlet.java:322)
13:51:48,203 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(
JspServlet.java:249)
13:51:48,203 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:717)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:290)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:206)
13:51:48,203 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilte
r.doFilter(ReplyHeaderFilter.java:96)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:235)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:206)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve
.invoke(StandardWrapperValve.java:235)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve
.invoke(StandardContextValve.java:191)
13:51:48,203 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssocia
tionValve.invoke(SecurityAssociationValve.java:190)
13:51:48,203 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValv
e.invoke(JaccContextValve.java:92)
13:51:48,203 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContext
EstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
13:51:48,203 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContext
EstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.in
voke(StandardHostValve.java:127)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.i
nvoke(ErrorReportValve.java:102)
13:51:48,203 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnec
tionValve.invoke(CachedConnectionValve.java:158)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.
invoke(StandardEngineValve.java:109)
13:51:48,203 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.s
ervice(CoyoteAdapter.java:330)
13:51:48,203 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.proc
ess(Http11Processor.java:829)
13:51:48,234 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http1
1ConnectionHandler.process(Http11Protocol.java:598)
13:51:48,234 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker
.run(JIoEndpoint.java:447)
13:51:48,234 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
13:51:48,234 ERROR [STDERR] javax.naming.NameNotFoundException: where not bound
13:51:48,234 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:771)
13:51:48,234 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming
Server.java:779)
13:51:48,234 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingS
erver.java:785)
13:51:48,234 ERROR [STDERR] at org.jnp.server.NamingServer.unbind(NamingServ
er.java:315)