Mal*_*iel 6 java jsp tomcat servlets
我正在使用在tomcat上运行的JSP和Java servlet开发一个相当简单的Web应用程序.我已经能够从servlet中设置会话中的属性,以便将信息传递给JSP,然后将其呈现给用户.我已经用不同类的几个不同对象完成了这个并且它运行良好.突然间,当我设置一个特定类型的对象(包含配置信息)时,该属性根本没有出现在JSP中.我设置的其他属性仍然存在,但配置对象完全丢失.我打印了属性名称列表,我使用的名称甚至没有(尽管我设置的其他属性的其他名称都存在).
什么可能导致这个?我的配置类没什么不同或奇怪的.我真的很感激任何关于什么样的事情可能导致这种行为的想法.我用Google搜索并搜索,找不到任何东西.
ETA:如果重要,则属性名称为"configuration".我找不到任何关于保留字或任何内容的东西......我在servlet中设置这个属性的功能与其他一些例如"user"相同.然后我重定向到一个试图获得用户和配置的JSP.所以一切都在同一时间进行.用户很好,而配置甚至没有出现在属性名称列表中.
ETA2:以下是日志中不断发生的异常:
java.lang.Exception
at pms.SessionListener.printStackTrace(Unknown Source)
at pms.SessionListener.attributeAdded(Unknown Source)
at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1498)
at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1390)
at org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:154)
at PMS.getTaskInfo(Unknown Source)
at PMS.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:282)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:357)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1687)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)Run Code Online (Sandbox Code Playgroud)
根据对该问题的评论:
会话绝对存在,我可以从JSP中的会话中同时检索servlet中设置的其他属性.这只是一个不会出现的特殊属性.我发现会话中没有很多东西不在那里,但不是为什么一个属性在别人做的时候不起作用.
然后有些东西已经删除或排除了属性.
session.removeAttribute("name");
Run Code Online (Sandbox Code Playgroud)
要么
session.setAttribute("name", null);
Run Code Online (Sandbox Code Playgroud)
甚至在JSP中
<c:set var="name" value="${null}" scope="session" />
Run Code Online (Sandbox Code Playgroud)
或者它可以是你自己设置null而不是完整的对象.
对于naildown这个和其他更好的,我会让属性实现HttpSessionBindingListener并转储堆栈valueUnbound().
public class Foo implements HttpSessionBindingListener {
@Override
public void valueBound(HttpSessionBindingEvent event) {
System.out.println("Value bound"); // Logger?
}
@Override
public void valueUnbound(HttpSessionBindingEvent event) {
System.err.println("Value unbound"); // Logger?
Thread.dumpStack();
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
出现问题的可能性有很多种。
您可以通过以下方法进行测试,看看究竟发生了什么。
您可以实现两个单独的侦听器接口来侦听特定会话事件:javax.servlet.http.HttpSessionListener和javax.servlet.http.HttpSessionAttributeListener
我将使用一个类来实现这两个接口,该类将记录每个事件期间发生的情况以及事件来自哪个会话。
您应该能够轻松地将侦听器添加到 web.xml 文件中,以便它们实际上被 tomcat 设置为会话上的侦听器。
编辑
您可以将以下类放置到 web.xml 中作为会话的侦听器。BalusC 和我本人都建议您尝试这种方法来调试问题。请幽默一下,如果您在“配置”属性的设置方式中发现任何有趣的内容,请告诉我们?
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListener implements HttpSessionListener, HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionActivationListener {
public void valueBound(HttpSessionBindingEvent event) {
System.out.println("valueBound: " + event.getName() + " : " + event.getValue());
System.out.println(" session: " + event.getSession().getId());
this.printStackTrace();
}
public void valueUnbound(HttpSessionBindingEvent event) {
System.out.println("valueUnbound: " + event.getName() + " : " + event.getValue());
System.out.println(" session: " + event.getSession().getId());
this.printStackTrace();
}
public void attributeAdded(HttpSessionBindingEvent event) {
System.out.println("attributeAdded: " + event.getName() + " : " + event.getValue());
System.out.println(" session: " + event.getSession().getId());
this.printStackTrace();
}
public void attributeRemoved(HttpSessionBindingEvent event) {
System.out.println("attributeRemoved: " + event.getName() + " : " + event.getValue());
System.out.println(" session: " + event.getSession().getId());
this.printStackTrace();
}
public void attributeReplaced(HttpSessionBindingEvent event) {
System.out.println("attributeReplaced: " + event.getName() + " : " + event.getValue());
System.out.println(" session: " + event.getSession().getId());
this.printStackTrace();
}
public void sessionCreated(HttpSessionEvent event) {
System.out.println("sessionCreated: " + event.getSession().getId());
this.printStackTrace();
}
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("sessionDestroyed: " + event.getSession().getId());
this.printStackTrace();
}
public void sessionDidActivate(HttpSessionEvent event) {
System.out.println("sessionDidActivate: " + event.getSession().getId());
this.printStackTrace();
}
@Override
public void sessionWillPassivate(HttpSessionEvent event) {
System.out.println("sessionWillPassivate: " + event.getSession().getId());
this.printStackTrace();
}
private void printStackTrace() {
try {
if (true) {
throw new Exception();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
请将上述类添加到您的代码中,然后将以下内容添加到您的过滤器映射和 servlet 映射之间的 web.xml 文件中:
<listener>
<listener-class><your.package.name>SessionListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4390 次 |
| 最近记录: |