1

このコード スニペットの何が問題なのかわかりません。

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()] でキューに入れArrayBlockingQueueられ、パラメータは通常の から取得されます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)
4

1 に答える 1