这是我的 JSP:
<HTML>
<BODY >
path : <%= application.getContextPath() %>
</BODY>
</HTML>
该文件在 Tomcat7 和 Tomcat6 中是正确的,但是当我在 Cpanel 托管的 Tomcat 5.32 中请求 JSP 页面时,出现以下异常:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 3 in the jsp file: /cal2.jsp
The method getContextPath() is undefined for the type ServletContext
1: <HTML>
2: <BODY>
3: path : <%= application.getContextPath() %>
4: </BODY>
5: </HTML>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:307)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:309)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:72
这个问题是如何引起的以及如何解决?
The getContextPath()
方法被添加到ServletContext
在规范的 2.5 版本中,但 Tomcat 5 仅实现了 2.4。然而,request.getContextPath()
做同样的事情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)