This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Attributes sent from JSP wont show in Servlet

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In my servlet:

I get output Null for both Attributes that I set. What am I doing wrong? Ive even tried using hidden form fields in the JSP to send. But still the result is Null in my servlet for some reason. I can see their outputted values in the JSP for sure when I use <%=%> . Any help is welcome
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you forwarded the request from jsp to servlet ?
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you set a request attribute in the JSP it is for that request. Request generally terminates at the JSP hence when you don't explixitly forward the request the request.setAttribute would only be available to that JSP page only and any included page.

The hidden form fields should work.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't understand your JSP: who sets the request attributes 'message', 'paramName' and 'jobs'? Were you trying to use 'request.getParameter(String)'?
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Tontang,

you can use hidden input fields (inside a form),

to retrieve them in your servlet use the getParameter(..) method.
(instead of getAttribute(..))

Herman
 
Manzar Zaidi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont see any problems with the code, it is doing what you rote it for,
When you write
If the attribute paramName is not set, it returns null.

Then if you set that back as a request attribute you get null on subsequent calls.


So that
Will return null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic