jsp中怎么有这种错误,The method getContextPath() is undefined for the type ServletContext

来源:百度知道 编辑:UC知道 时间:2024/05/15 13:07:26
明明就有这个方法啊,

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 4 in the jsp file: /MyJsp.jsp
The method getContextPath() is undefined for the type ServletContext
1: <%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
2: <%
3: //String path = request.getContextPath();
4: String path = config.getServletContext().getContextPath();
5: out.println(path);
6: String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
7: %>

应该是Servlet版本的问题,低版本的request对象没这个方法。

不同应用服务器Servlet版本不同,移植的时候会出现问题。

注意你引的包的版本,低版本的就没有此方法。

getContextPath()
方法未定义错误吗!
undefined for the type ServletContext