【发布时间】: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());
%>
我在lib 的WEB-INF 文件夹下使用了以下罐子。
jasper.jarorg.apache.jasper.jarjavax.servlet-api-3.0.jarjavax.el-api.jarjavax.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 扩展页面指令的示例。
【问题讨论】: