我正在使用Eclipse IDE来处理servlet。我创建了一个maven项目来处理异步servlet 3.0并添加了适当的依赖项。代码request.isAsyncSupported()
返回true。现在,当我调用servlet时,它会出现此错误
WARN:oejs.ServletHandler:/ testplugin / JsonServlet java.lang.IllegalStateException:DISPATCHED,initial 在org.eclipse.jetty.server.Request.getAsyncContext(Request.java:325) 在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.security.SecurityHandler.handle(SecurityHandler.java:524) 在org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233) 在org.eclipse.jetty.server.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.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) 在org.eclipse.jetty.server.Server.handle(Server.java:351) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890) at org.eclipse.jetty.server.AbstractHttpConnection $ RequestHandler.headerComplete(AbstractHttpConnection.java:944) 在org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:634) 在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.run(SelectChannelEndPoint.java:45) 在org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) 在org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run(QueuedThreadPool.java:534) 在java.lang.Thread.run(未知来源)。
我在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
由于
答案 0 :(得分:0)
这是代码错误,如果我们在getAsyncRequest()
之前尝试获取request.startAsync()
将产生错误。