Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method getContextPath() is undefined for the type ServletContext

Tags:

java

jsp

Here is my JSP:

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

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?

like image 842
amir2 taghvaei Avatar asked Jul 09 '26 13:07

amir2 taghvaei


1 Answers

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.

like image 157
Mac Avatar answered Jul 12 '26 03:07

Mac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!