Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Attributes sent from JSP wont show in Servlet

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you forwarded the request from jsp to servlet ?
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)'?
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Dinner will be steamed monkey heads with a side of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic