【问题标题】:Jsp extends page directives exception: Unable to compile class for JSP:Jsp 扩展页面指令异常:无法为 JSP 编译类:
【发布时间】:2015-06-02 07:08:56
【问题描述】:

我正在尝试通过使用 JSP 扩展页面指令来创建一个示例,首先我在我的项目源区域中构建了一个简单的 java 类文件。项目正在 Eclipse IDE 中构建。

代码在这里:

package com.coderbd.extend;

public class Test {

    public String testMethod(){
        return "Hello";
    }

}

首先在 JSP 页面上,我使用扩展页面指令扩展了类,例如:<%@ page extends="com.coderbd.extend.Test" %> 然后在我的index.jsp 页面中,我创建了Test 类的对象,例如:

<%
    Test t= new Test();
    t.testMethod();
%>

最后尝试打印:

<%
    out.println(""+ testMethod());
%>

我在libWEB-INF 文件夹下使用了以下罐子。

  1. jasper.jar
  2. org.apache.jasper.jar
  3. javax.servlet-api-3.0.jar
  4. javax.el-api.jar
  5. javax.servlet-3.0.jar

但是我明白了,我的 Tomcat 服务器出现以下错误:

HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: [32] in the generated java file: [E:\The Java Spring Tutorial Learn Java's Popular Web Framework\JSP\work-space\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\jsp-sec-4-lec-3\org\apache\jsp\index_jsp.java]
The method getServletConfig() is undefined for the type index_jsp

An error occurred at line: [33] in the generated java file: [E:\The Java Spring Tutorial Learn Java's Popular Web Framework\JSP\work-space\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\jsp-sec-4-lec-3\org\apache\jsp\index_jsp.java]
The method getServletConfig() is undefined for the type index_jsp

An error occurred at line: [54] in the generated java file: [E:\The Java Spring Tutorial Learn Java's Popular Web Framework\JSP\work-space\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\jsp-sec-4-lec-3\org\apache\jsp\index_jsp.java]
The method getPageContext(Servlet, ServletRequest, ServletResponse, String, boolean, int, boolean) in the type JspFactory is not applicable for the arguments (index_jsp, HttpServletRequest, HttpServletResponse, null, boolean, int, boolean)

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

请帮助我修复使用 jsp 扩展页面指令的示例。

【问题讨论】:

    标签: java jsp tomcat


    【解决方案1】:

    从 WEB-INF/lib 中删除所有这些 jar。这些是 Tomcat 内部使用的 jar 文件。它们不应该在您的网络应用程序中。

    并删除extends="com.coderbd.extend.Test":这没有任何意义。您的 JSP 创建一个 Test 实例并使用它。它不需要(也不能)扩展它。

    【讨论】:

    • 我已经使用extends关键字解决了这个问题,实际上我想使用extends。谢谢大家给我建议。
    猜你喜欢
    • 1970-01-01
    • 2017-05-12
    • 2017-12-13
    • 1970-01-01
    • 2017-12-13
    • 2015-11-15
    • 2021-10-04
    • 2016-09-15
    相关资源
    最近更新 更多