Hi All,
How can I get a handle of HttpServletRequest throught a RequestContext. My motive is to upload a file using multipart and the MultipartParser Class.
I would be great full if you can help me out.
Thank in advance.
Regards,
Ravi.
Hi All,
How can I get a handle of HttpServletRequest throught a RequestContext. My motive is to upload a file using multipart and the MultipartParser Class.
I would be great full if you can help me out.
Thank in advance.
Regards,
Ravi.
Bye!Code:ServletExternalContext externalContext = (ServletExternalContext)context.getExternalContext(); HttpServletRequest resquest = externalContext.getRequest();
Thanks a lot,
My apologies for bumping an old post back from the dead, but...
The solution above does not work for me. externalContext.getRequest() is protected. I need to have access to the request.getServerName() method. I have a solution that involves using reflection to access the request, but it is messy and I would really like to replace it.
Here is the reflection code:
Code:ServletExternalContext servletExternalContext = ((ServletExternalContext) (context.getExternalContext())); HttpServletRequest request; Field requestField = ServletExternalContext.class.getDeclaredField("request"); requestField.setAccessible(true);
Is there a better way?
Have you tried externalContext.getNativeRequest() ? You should be able to cast this into an HttpServletRequest, and not deal with reflection at all.
That did the trick, thank you!