Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Setting Attribute from JSP  RSS feed

 
Sameer Simha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to set and attribute in the JsP and trying to retrieve from the servlet. But I get "null" as value when I try accessing. Following is the code snippet.
The hidden parameter was my second option as I had to push my code




Servlet

String thisAttribute = (String) request.getAttribute(TITLE_TO_EXPORT);

When I click on a button the form gets submitted and the URL points to this servlet so I know that the request object is not getting tampered. But I really have no clue why I am being returned a null value.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set attribute to request when you create a jsp page the attribute gets set in the request that is currently running. And when the page is formed the request ends and is destroyed so if your attribute is inside it it gets destroyed as well.

And when you push a button on jsp page a new request is created but since it is a new request it naturally does not have the attribute set.

But maybe I am missing something here since this seems such a simple concept. What exactly are you trying to do?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!