我试图通过使用JSP扩展页面指令来做一个例子,首先,我在项目源区域中构建了一个简单的java类文件。 Project正在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.jar
使用了以下广告罐。
org.apache.jasper.jar
javax.servlet-api-3.0.jar
javax.el-api.jar
javax.servlet-3.0.jar
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)
但是我知道,我的Tomcat服务器出现以下错误:
{{1}}
请帮我修复使用jsp extends page指令的例子。
答案 0 :(得分:0)
从WEB-INF / lib中删除所有这些jar。这些是Tomcat内部使用的jar文件。它们不应该在您的webapp中。
并删除extends="com.coderbd.extend.Test"
:它没有任何意义。您的JSP创建了Test
和使用的实例。它不需要(并且不能)扩展它。