Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes Cannot set attribute in request in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Cannot set attribute in request in jsp" Watch "Cannot set attribute in request in jsp" New topic
Author

Cannot set attribute in request in jsp

rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
Hello to all,

I am trying to send an object from one jsp to another jsp through request object, I donot want to use hidden parameters. I tried "request.setAttribute(name,object)" in jsp but unable to get the same value on second page.
Also I have tried a simple example similar as shown below

first.jsp


second.jsp


but I get output as

but from servlet it works fine. I thing we cannot set attribute in jsp page. So suggest me how can I pass the parameter to next page after clicking on the submit button?

Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35256
    
    7
The fact that you're calling request.setAttribute should tell you something. Whatever attributes are set in a request, are lost when the request is finished - which it will be right after the JSP page has been generated. (That's long before second.jsp is accessed.)

If you want to set attributes that exist for longer than a request/response cycle, use session attributes (for a particular user) or application attributes (which are visible to all users).

Alternatively, you could use a hidden parameter in the form. That's likely a better solution than using attributes, assuming that it's OK for the user to see the value of the attribute.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Cannot set attribute in request in jsp
 
Similar Threads
difference between servlets parameters and arguments
request object is not propagated to next page
problem with request.setAttribute in jsp
request attribute NULL in JSP page
Accessing variables from EL