0

Eclipse IDE を使用してサーブレットで作業しています。非同期サーブレット 3.0 で動作する Maven プロジェクトを作成し、それに適切な依存関係を追加しました。コードrequest.isAsyncSupported()は true を返します。サーブレットを呼び出すと、このエラーが発生します

警告:oejs.ServletHandler:/testplugin/JsonServlet java.lang.IllegalStateException: DISPATCHED,initial at org.eclipse.jetty.server.Request.getAsyncContext(Request.java:325) at com.ajitpals.search.grid.fs.JsonServlet org.eclipse.jetty の javax.servlet.http.HttpServlet.service(HttpServlet.java:847) の javax.servlet.http.HttpServlet.service(HttpServlet.java:734) の .doGet(JsonServlet.java:42)。 org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486) で org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java: 119) org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233) で org.eclipse.jetty.server で org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524) で.org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413) の handler.ContextHandler.doHandle(ContextHandler.java:1065) org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java: 192) org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999) で org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) で org.eclipse.jetty .server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) at org.eclipse.jetty.server.Server.handle(Server.java:351) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java) :454) org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890) で org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler で。org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:634) の headerComplete(AbstractHttpConnection.java:944) org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230) の org.eclipse .jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1. run(SelectChannelEndPoint.java:45) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) ) java.lang.Thread.run (不明なソース) で。org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) で org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) で.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) at org.eclipse.jetty.util. thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) で java.lang.Thread.run (不明なソース)。org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) で org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) で.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) at org.eclipse.jetty.util. thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) で java.lang.Thread.run (不明なソース)。eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) at java.lang.Thread.run(Unknown)ソース)。eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) at java.lang.Thread.run(Unknown)ソース)。

Maven プロジェクトに次の依存関係を追加しました。

 <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1-b08</version>
</dependency>

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>9.0.2.v20130417</version>
</dependency>

サーブレットコードは

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    if(request.isAsyncSupported()){

    final AsyncContext asynCtx = request.getAsyncContext();

    //Set the timeout
    asynCtx.setTimeout(35000);

    //Add the listeners.
    asynCtx.addListener(new AsyncListener() {

        public void onTimeout(AsyncEvent arg0) throws IOException {
            System.out.println("timeout");              
        }

        public void onStartAsync(AsyncEvent arg0) throws IOException {
            System.out.println("on start");             
        }

        public void onError(AsyncEvent arg0) throws IOException {
            System.err.println("on error");             
        }

        public void onComplete(AsyncEvent arg0) throws IOException {
            System.out.println("On complete");              
        }
    });

    //start the new thread.
    asynCtx.start(new Runnable() {

        public void run() {
            try{
                asynCtx.getResponse().getWriter().write(MessageFormat.format("<h1>Process task id : [{0}] and Name [{1}]</h1>", 
                        Thread.currentThread().getId()));
            }catch(Exception ex){
                System.err.println("async error " + ex.getMessage());
            }
        }
    });
    }
}

同様の問題に直面した人はいますか?どうすれば解決できますか?

編集:

サーブレットで次のエラーが発生することもあります

PWC6345: There is an error in invoking javac. A full JDK (not just JRE) is required Caused by:org.apache.jasper.JasperException:PWC6345: There is an error in invoking javac. A full JDK (not just JRE) is required

ありがとう

4

1 に答える 1

0

getAsyncRequest()beforeを取得しようとrequest.startAsync() すると、エラーが発生します。

于 2013-05-02T14:06:54.490 に答える