Open GoogleCodeExporter opened 9 years ago
I've also tried with
ServletRequestAttributes sra=(ServletRequestAttributes)
RequestContextHolder.currentRequestAttributes();
but doesn't work.
Are there in place any workaround??
Original comment by spiderj...@gmail.com
on 27 Dec 2010 at 3:34
May be possible i've found a possible workaround for this:
just declare in the web.xml of the application this listener (from spring
distr.)
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
In the spring bean service just declare this:
@Autowired
private HttpServletRequest request;
And seems it work.
Done.
Original comment by spiderj...@gmail.com
on 27 Dec 2010 at 4:05
The above is not working for me.
Do we have any solution on this?
Original comment by ritesh.s...@chleon.com
on 15 Jun 2011 at 6:01
Mentioning the code which worked for me
Change your web.xml
-------------------
<filter>
<filter-name>springRequestFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springRequestFilter</filter-name>
<url-pattern>/your_pattern/*</url-pattern>
</filter-mapping>
And in the ServiceImpl class, you can access the request attribute by using
ServletRequestAttributes sra =
((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes());
sra.getRequest();
Hope it'll help
Original comment by ritesh.s...@chleon.com
on 17 Jun 2011 at 4:49
[deleted comment]
@Paresh I think that your approach is not Thread Safe.
Original comment by vijaz...@gmail.com
on 14 Sep 2011 at 7:22
[deleted comment]
Thanks Ritesh.Your suggested approach worked.
Change your web.xml
-------------------
<filter>
<filter-name>springRequestFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springRequestFilter</filter-name>
<url-pattern>/your_pattern/*</url-pattern>
</filter-mapping>
And in your Service Impl class, add
@Autowired
private HttpServletRequest request;
And then you can access the http session as
request.getSession()or can set it like
request.getSession().setAttribute(<variable>,<val> );
Vikram
Original comment by kohli.Vi...@gmail.com
on 11 Mar 2012 at 5:26
Original issue reported on code.google.com by
bmakar...@gmail.com
on 1 Oct 2010 at 4:35