我正在使用 Eclipse IDE 来处理 servlet。我创建了一个使用异步 servlet 3.0 的 maven 项目,并为其添加了适当的依赖项。代码request.isAsyncSupported()
返回真。现在,当我调用 servlet 时,它会出现此错误
WARN: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 .doGet(JsonServlet.java:42) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:734) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 在 org.eclipse.jetty。 servlet.ServletHolder.handle(ServletHolder.java:594) 在 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) .handler.ContextHandler.doHandle(ContextHandler.java:1065) 在 org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413) 在 org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java: 192) 在 org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) 在 org.eclipse.jetty 的 org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999) .server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) 在 org.eclipse.jetty.server.Server.handle(Server.java:351) 在 org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java :454) 在 org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890) 在 org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler。headerComplete(AbstractHttpConnection.java:944) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:634) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230) at org.eclipse .jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) 在 org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) 在 org.eclipse.jetty.io.nio.SelectChannelEndPoint$1。在 org.eclipse.jetty.util.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) 在 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) 运行(SelectChannelEndPoint.java:45) ) 在 java.lang.Thread.run(Unknown Source)。org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) 的 parseAvailable(HttpParser.java:230) org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) 的 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(Unknown Source)。org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) 的 parseAvailable(HttpParser.java:230) org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) 的 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(Unknown Source)。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>
servlet 代码是
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());
}
}
});
}
}
有没有人遇到过类似的问题,我们该如何解决。
编辑:
有时servlet也会出现以下错误
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
谢谢