cannot find symbol: method getServletContext()

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

 

转载于:https://www.cnblogs.com/yuxiaoqi/p/4797412.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值