3

我在 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 下的一般配置问题,因为在桌面上编译和执行的相同代码可以正常工作。

4

2 回答 2

4

JSP 在 Android 上是不可能的。

或者更准确地说,在 Android 设备上编译 JSP 是不可能的。

现有的 JspServlet 实现将尝试将*.java源代码作为*.class文件编译到目录中,标准javac不存在,因此您会认为您可以依靠 Eclipse 编写的 JDT 实现来执行此操作,但由于某些基本原因,即使这样也行不通.

  1. 基本类库不存在于 JDT 编译器查找的标准位置。这就是您看到所有“无法解决”错误的原因。
  2. 编译到*.class文件在 android 上毫无意义,因为实际的 Android 设备本身不理解*.class文件。它不是 Java,而是 Dalvik,它恰好(在开发/构建时)与 Java 兼容。
  3. Android 的 Dalvik VM 需要 dexified 字节码,JDT 编译器无法生成。
  4. 我知道没有设备上的 dexify 工具、库或实用程序可以为您完成最后一步。如果确实存在,您将需要分叉并修改 JSP 实现以包含这一额外步骤。

如果你想在 JSP 中开发并在 android 上拥有一个 webapp,这就是你需要做的:

  1. 从 web.xml 或 webdefault.xml 中删除 JspServlet。无论如何,您无法在Android上使用它。
  2. 在您的开发机器上预编译您的 JSP。
  3. 更新您的WEB-INF/web.xml以包含已编译的 JSP 引用。看看那里的各种 JSPC 工具,它们都支持这个概念(作为适合包含的 XML 片段,或者通过直接修改现有的WEB-INF/web.xml.
  4. 使用 i-jetty 项目中概述的技术对后编译的 WAR 文件进行 Dexify。

这将允许您使用 JSP 进行开发,并在 Android 上使用它们,但不是作为原始*.jsp文件本身,而是作为编译后的文件*.class files(然后将其分解为 Android 字节码格式)。

于 2013-06-05T17:00:18.843 回答
0

Jetty 不就是为了这个目的吗?

http://www.eclipse.org/jetty/documentation/current/configuring-jsp.html#jsp-support

于 2014-02-14T10:59:23.403 回答