0

I have some old code in which the programmer has passed servletContext into the method. But now for some upgradation I need to use HttpServletRequest in same method, I cannot change the old code, so passing the request object is not an option. So is there any way throught which I can get hold of request object.

I am using java 1.6 and tomcat 6. Its a servlet jsp application and not spring or struts. Can it be done? If yes then how should I do it.

pramodpotdar17
  • 691
  • 5
  • 11
  • You will have to change the old code to pass the request. The method can get the context from the request, but not the other way around, as requests aren't unique within the context. – user207421 Sep 14 '17 at 05:33
  • Its huge application, I will have to make changes on around 1000 lines on multiple pages. Thats why I need an work around. Thanks anyways. – pramodpotdar17 Sep 14 '17 at 06:09

1 Answers1

0

You can use setAttribiute method and add request to the context before passing it to your method.

Javadoc: https://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletContext.html

arthooz
  • 101
  • 1
  • 6