对于ServletContext类型

对于ServletContext类型

本文介绍了对于ServletContext类型,未定义方法getContextPath()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的JSP:

<HTML>
<BODY >
path : <%= application.getContextPath() %>
</BODY>
</HTML>

此文件在Tomcat7和Tomcat6中是正确的,但是当我在Cpanel托管的Tomcat 5.32中请求JSP页面时,出现以下异常:

This file is correct in Tomcat7 and Tomcat6, but when I request the JSP page in Tomcat 5.32 of my Cpanel hosting, I get the following exception:

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

此问题是怎么引起的,我该如何解决?

How is this problem caused and how can I solve it?

推荐答案

在规范的2.5版中,getContextPath()方法已添加到ServletContext中,但是Tomcat 5仅实现2.4.但是,request.getContextPath()做同样的事情.

The getContextPath() method was added to ServletContext in version 2.5 of the spec, but Tomcat 5 only implements 2.4. However, request.getContextPath() does the same thing.

这篇关于对于ServletContext类型,未定义方法getContextPath()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 06:17