Android上的JSP编译(嵌入式Jetty)
作者:互联网
我在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) {
}
}
我将Web服务器文件(静态内容和jsp文件)放置在外部存储的“ / web /”目录下(它适用于静态内容,我已在清单文件中设置了读写权限).
我认为这是Android下的一般配置问题,因为在桌面上编译和执行的相同代码可以正常工作.
解决方法:
在Android上无法使用JSP.
或者更准确地说,无法在Android设备上编译JSP.
现有的JspServlet实现将尝试将* .java源代码编译为* .class文件到目录中,而标准的javac不存在,因此您会认为可以依靠Eclipse编写的JDT实现来做到这一点,但是即使如此由于某些基本原因而无法使用.
> JDT编译器寻找的标准位置中没有基本类库.这就是为什么您看到所有“无法解决”错误的原因.
>在Android上编译为* .class文件是没有意义的,因为实际的Android设备本身无法理解* .class文件.它不是Java,而是Dalvik,它恰好与Java兼容(在开发/构建时).
> Android的Dalvik VM需要精制的字节码,而JDT编译器无法生成该字节码.
>我知道没有设备上的dexify工具,库或实用程序可以为您完成最后一步.如果确实存在,则需要分叉并修改JSP实现以包括这一额外步骤.
如果要使用JSP开发并在android上拥有一个webapp,则需要执行以下操作:
>从web.xml或webdefault.xml中删除JspServlet.无论如何,您不能在Android上使用它.
>在开发计算机上预编译JSP.
>更新您的WEB-INF / web.xml以包括已编译的JSP参考.看看那里的各种JSPC工具,它们都支持此概念(作为适合包含的XML片段,或者通过直接修改现有的WEB-INF / web.xml来实现).
>使用i-jetty项目中概述的技术对后编译的WAR文件进行解毒.
这将允许您使用JSP进行开发,并在Android上使用它们,而不是作为原始* .jsp文件本身,而是作为已编译的* .class文件(然后将其精化为Android字节码格式).
标签:embedded-jetty,android,jsp 来源: https://codeday.me/bug/20191030/1970777.html