我不确定此代码段有什么问题:
public class RequestProcessor extends Thread{
private ServletContext context;
private HttpServletRequest request;
private HttpServletResponse response;
public RequestProcessor(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) {
this.context = servletContext;
this.request = request;
this.response = response;
handler = HandlerFactory.getFactory(request);
start();
}
public void run(){
RequestDispatcher dispatcher = context.getRequestDispatcher("/index.jsp");
try {
dispatcher.forward(request, response);
} catch (ServletException e) {
} catch (IOException e) {
}
}
这些线程enqueue()
在 a 中排队 [method],ArrayBlockingQueue
参数取自 normal HttpServlet
。
因此,来自 HttpServlet 的 doGet() :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
scheduler.enqueue(getServletContext(), request, response);
}
我有一个 Java 异常,转发有问题。
我的代码有什么问题?
编辑:
看看这个堆栈跟踪:
Servlet.service() for servlet RequestDispatcher threw exception
java.lang.NullPointerException
at org.apache.catalina.connector.Request.notifyAttributeAssigned(Request.java:1563)
at org.apache.catalina.connector.Request.access$000(Request.java:107)
at org.apache.catalina.connector.Request$3.set(Request.java:3369)
at org.apache.catalina.connector.Request.setAttribute(Request.java:1515)
at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:542)
at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at source.RequestProcessor.run(RequestProcessor.java:42)
Exception in thread "Thread-3" java.lang.NullPointerException
at org.apache.catalina.connector.Request.notifyAttributeAssigned(Request.java:1563)
at org.apache.catalina.connector.Request.access$000(Request.java:107)
at org.apache.catalina.connector.Request$3.set(Request.java:3369)
at org.apache.catalina.connector.Request.setAttribute(Request.java:1515)
at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:542)
at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at source.RequestProcessor.run(RequestProcessor.java:42)