• Post Reply Bookmark Topic Watch Topic
  • New Topic

accessing HttpServletRequest object from JSP Function  RSS feed

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the subject says it all, but...
I have a JSP private function inside which I want to access HttpServletRequest object, just as I would outside of private function using request.getParameter(...). How should I initialize HttpServletRequest object inside the private function?

thanks,
Alex
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should just pass your request object to your function like so:
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, the request object is created and initialized by the application server from the HTTP request received from the browser.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. But I can access it without passing as a parameter as well, no? May be from a session object. Just curious.

Alex
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you cannot access it in any way without passing it.
[ December 07, 2004: Message edited by: Bear Bibeault ]
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason why request/response object is not accessible without passing it?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How could they be? The request and response are passed to the service() method of the JSP. A call from that method to your defined method must pass the reference along.

The only way to have made them available to methods defined in a JSP* without passing them along would have been to make them instance variables of the JSP servlet. Which of course can't happen due to thread safety issues.

*My opinion: bad idea. Very bad idea.
[ December 07, 2004: Message edited by: Bear Bibeault ]
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Bear!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!