• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request Attribute doubt?

 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I tried the following and got end up with a null pointer exception!

The test.jsp,
 
Nikhil Jain
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the doGet being called. Are you forwarding it to the Servlet or something....
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,

I'm using a servlet-mapping element as below,
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi Shankar Kumar Sankararaj ,

 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srinivas,

I'm not able to follow...1.4 sends the response form to user.
1.5 request ends here. (request and all attributes gone
with wind)

Why and how??
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shankar,

Important to know What specs guarentee you!

SRV.4.10 Lifetime of the Request Object

.
[ April 26, 2007: Message edited by: Srinivasan thoyyeti ]
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user is making two requests.

The first one for test.jsp (the form page) by typing the correct url in the browser, I guess.
The second for "ExampleServlet" (this requested is triggered when he presses the "SUBMIT" button).
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the catch! Srinivasan, thanks for bringing the bits from the servlet specs.
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Then in such a situation (for the scenario as above where we have to go from a jsp to a servlet), we can only place this in the application scope or session scope. Am I right??
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what else could be the way to use the request attribute for the code above?? I want to set the attribute in the jsp and get it in the servlet. Should I get a request dispatcher and forward the request and response or Should I store this as a session attribute which I don't want since I'm not going to use session for the above example??
[ April 26, 2007: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then in such a situation (for the scenario as above where we have to go from a jsp to a servlet), we can only place this in the application scope or session scope. Am I right??


You could put some values in html hidden fields too. They will be sent in the request as strings.
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,

The question is when I set the request attribute in a jsp and when hitting the submit button, the jsp calls a servlet and in that servlet, I'm trying to get the values of the attribute using getAttribute method and when I tried this, it gave me NullPointerException. I later understood that when the service method of the jsp finishes the request attributes gets vanished which is why I'm getting a null pointer. So like you say when I use a hidden field it is again the same or??
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I got confused. Putting them in hidden fields, you would have to use getParameter to retrieve them, not getAttribute. Please forget about this.
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,

Then what would be the solution to my question?? I want to use only request attribute.
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I try doing something with a requestdispatcher like this in my jsp??

RequestDispatcher view = request.getRequestDispatcher("/ExampleServlet")?? Is the argument correct or should it only point to a jsp???
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, because the request is generated by the web client after submission. You can do it with servlet->jsp, not jsp->servlet. If you need to store something beyong the scope of a request, then you'll have to put it in session or application scope.
 
Joe Harry
Ranch Hand
Posts: 10082
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guessed it and you confirmed it Satou. You help me a lot. Thanks once again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic