有关getServletContext

lyj57 2013-04-24 11:52:27
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

求助啊!这要怎么解决
...全文
617 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
还原本质 2015-05-18
  • 打赏
  • 举报
回复
引用 3 楼 jia20003 的回复:
request.getSession().getServletContext().getRealPath("/"));
学习了,谢谢
菖蒲老先生 2013-04-24
  • 打赏
  • 举报
回复
压根就没这方法,你代码编译不报错么。。。
  • 打赏
  • 举报
回复
getServletContext() 这个方法在Servlet 3.0规范里才有,你是tomcat6?要tomcat7才行的
gloomyfish 2013-04-24
  • 打赏
  • 举报
回复
request.getServletContext().getRealPath("/")
在高版本的servlet中已经不支持这个API了
gloomyfish 2013-04-24
  • 打赏
  • 举报
回复
request.getSession().getServletContext().getRealPath("/"));

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧