我在 Android 平台上运行 Jetty 来提供静态 html 页面和 servlet。现在我尝试添加对 JSP 页面的支持,但是当我要求任何 jsp 时出现此异常:
HTTP ERROR 500
Problem accessing /time.jsp. Reason:
Server Error
Caused by:
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
PWC6199: Generated servlet error:
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
PWC6199: Generated servlet error:
The type java.lang.Throwable cannot be resolved. It is indirectly referenced from required .class files
PWC6199: Generated servlet error:
The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
PWC6199: Generated servlet error:
org.apache.jasper.runtime.HttpJspBase cannot be resolved to a type
PWC6199: Generated servlet error:
org.apache.jasper.runtime.JspSourceDependent cannot be resolved to a type
PWC6199: Generated servlet error:
JspFactory cannot be resolved to a type
PWC6199: Generated servlet error:
JspFactory cannot be resolved
PWC6199: Generated servlet error:
java.util.List cannot be resolved to a type
PWC6199: Generated servlet error:
Syntax error, parameterized types are only available if source level is 1.5 or greater
PWC6199: Generated servlet error:
String cannot be resolved to a type
PWC6199: Generated servlet error:
org.glassfish.jsp.api.ResourceInjector cannot be resolved to a type
PWC6199: Generated servlet error:
java.util.List cannot be resolved to a type
PWC6199: Generated servlet error:
Syntax error, parameterized types are only available if source level is 1.5 or greater
PWC6199: Generated servlet error:
String cannot be resolved to a type
PWC6199: Generated servlet error:
_jspx_dependants cannot be resolved to a variable
PWC6199: Generated servlet error:
HttpServletRequest cannot be resolved to a type
PWC6199: Generated servlet error:
HttpServletResponse cannot be resolved to a type
PWC6199: Generated servlet error:
java.io.IOException cannot be resolved to a type
PWC6199: Generated servlet error:
ServletException cannot be resolved to a type
PWC6199: Generated servlet error:
PageContext cannot be resolved to a type
PWC6199: Generated servlet error:
HttpSession cannot be resolved to a type
PWC6199: Generated servlet error:
ServletContext cannot be resolved to a type
PWC6199: Generated servlet error:
ServletConfig cannot be resolved to a type
PWC6199: Generated servlet error:
JspWriter cannot be resolved to a type
PWC6199: Generated servlet error:
Object cannot be resolved to a type
PWC6199: Generated servlet error:
JspWriter cannot be resolved to a type
PWC6199: Generated servlet error:
PageContext cannot be resolved to a type
PWC6199: Generated servlet error:
_jspxFactory cannot be resolved
PWC6199: Generated servlet error:
_jspx_resourceInjector cannot be resolved to a variable
PWC6199: Generated servlet error:
org.glassfish.jsp.api.ResourceInjector cannot be resolved to a type
PWC6197: An error occurred at line: 3 in the jsp file: /time.jsp
PWC6199: Generated servlet error:
java.util.Date cannot be resolved to a type
PWC6199: Generated servlet error:
Throwable cannot be resolved to a type
PWC6199: Generated servlet error:
SkipPageException cannot be resolved to a type
PWC6199: Generated servlet error:
ServletException cannot be resolved to a type
PWC6199: Generated servlet error:
_jspxFactory cannot be resolved
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:129)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:299)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:392)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:856)
Powered by Jetty://
这是我主要活动的配置代码:
public void startServer()
{
server = new Server(8080);
System.setProperty("org.apache.jasper.compiler.disablejsr199", "true");
// Create a resource handler for static content.
ResourceHandler staticResourceHandler = new ResourceHandler();
staticResourceHandler.setResourceBase(Environment.getExternalStorageDirectory().getAbsolutePath() + "/web/static/");
staticResourceHandler.setDirectoriesListed(false);
// Create context handler for static resource handler.
ContextHandler staticContextHandler = new ContextHandler();
staticContextHandler.setContextPath("/static");
staticContextHandler.setHandler(staticResourceHandler);
// Create WebAppContext for JSP files.
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/");
webAppContext.setResourceBase(Environment.getExternalStorageDirectory().getAbsolutePath() + "/web/");
webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
// Create servlet context handler for main servlet.
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/servlet");
servletContextHandler.setResourceBase(Environment.getExternalStorageDirectory().getAbsolutePath() + "/web/servlet/");
terminalServlet = new TerminalServlet(this);
networkServlet = new NetworkDrawerServlet(this);
servletContextHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
servletContextHandler.addServlet(new ServletHolder(terminalServlet),"/terminal");
servletContextHandler.addServlet(new ServletHolder(networkServlet),"/topology");
//servletContextHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*");
// Create a handler list to store our static, jsp and servlet context handlers.
HandlerList handlers = new HandlerList();
handlers.setHandlers(new org.eclipse.jetty.server.Handler[] { staticContextHandler, webAppContext, servletContextHandler });
// Add the handlers to the server and start jetty.
server.setHandler(handlers);
try {
server.start();
} catch (Exception e) {
}
}
我将网络服务器文件(静态内容和 jsp 文件)放在外部存储的“/web/”目录下(它适用于静态内容,我在清单文件中设置了读写权限)。
我认为这是 Android 下的一般配置问题,因为在桌面上编译和执行的相同代码可以正常工作。