码迷,mamicode.com
首页 > 其他好文 > 详细

cannot find symbol: method getServletContext()

时间:2015-09-10 12:38:14      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

Description

compile:
[javac] Compiling 1 source files to C:\...\workspace\proj\build\WEB-INF\classes
[javac] C:\...\workspace\proj\src\main\Helper.java:26: cannot find symbol
[javac] symbol  : method getServletContext()
[javac] location: interface javax.servlet.http.HttpServletRequest
[javac]     return getURISet(request.getServletContext());
[javac]                       ^
[javac] Note: C:\...\workspace\proj\src\main\Helper.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error

Solution

The getServletContext() method is introduced in Servlet 3.0, not 2.3. But if you want to get the ServletContext then an alternative method to get it is:

1 ServletContext context = request.getSession().getServletContext();
2 
3 if (username != "" & username != null ) {
4     context.setAttribute("savedUserName", username);
5 }
6 writer.println("Context Parameter : " + (String)context.getAttribute("savedUserName"));

This way you can get the stored Request Parameter Value in different browser....

Reference

 

cannot find symbol: method getServletContext()

标签:

原文地址:http://www.cnblogs.com/yuxiaoqi/p/4797412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!