当前位置: 代码迷 >> Java Web开发 >> 相关getServletContext
  详细解决方案

相关getServletContext

热度:431   发布时间:2016-04-14 14:04:39.0
有关getServletContext
public void parseRequest(HttpServletRequest request){
        System.out.println("parseRequest:"+request.getParameter("username"));
System.out.println("realPath:"+request.getServletContext().getRealPath("/"));
path=request.getServletContext().getRealPath("/test_db.accdb");

ConnectAccessFile(request.getParameter("username"));

}
上面是TestAction.java中的几句,运行提示错误
The method getServletContext() is undefined for the type HttpServletRequest
The method getServletContext() is undefined for the type HttpServletRequest

求助啊!这要怎么解决
------解决思路----------------------
getServletContext()
这个方法在Servlet 3.0规范里才有,你是tomcat6?要tomcat7才行的
------解决思路----------------------
request.getServletContext().getRealPath("/")

在高版本的servlet中已经不支持这个API了