Java常见错误汇总

时间:2022-09-17 10:07:36

The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files

是缺少serverlet的引用库,解决如下
1.工程右键-properties->java build path
2.在java build path的libraries tab页中选择Add external Jars...按钮
3. 选择eclipse的安装目录,我的是绿色版本,我本机的路径如下,你自己需要根据自己的路径查找添加。E:\eclipse-java-indigo-SR1-win32\eclipse\plugins 选择javax.servlet.jsp_2.0.0.v201101211617.jar;javax.servlet_2.5.0.v201103041518.jar 进行添加即可
注释:由于版本不同,文件包名可能稍有区别。

the import javax.servlet cannot be resolved

同上面的方法,导入servlet-api.jar
The method getServletContext() is undefined for the type HttpServletRequest
在高版本的servlet中已经不支持下面这个API了:
request.getServletContext().getRealPath("/")
需改为: request.getSession().getServletContext().getRealPath("/"));