Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet and SimpleTagSupport

 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I pass a parameter from a servlet to a SimpleTag?.

Say, I am setting a parameter in servlet as :-
request.setAttribute("test", "test Value");

What do I do in SimpleTag to get the value of test from the attribue. I tried getJspContext().getAttribute("test"), but it returns Null
 
Anurag Saksena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try..

PageContext pageContext = (PageContext) getJspContext();
pageContext.getAttribute("test", REQUEST_SCOPE);

-a.
==========
SCJP 1.4
SCWCD 1.4
 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anurag Saksena:


PageContext pageContext = (PageContext) getJspContext();


JspContext is the superclass of PageContext.. so it gives me a class cast error !!. Is there any other way ??. Or Should I use the classic Tag handlers with pageContext ???

 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the classic Tag Handler works ..
pageContext.getAttribute("test",PageContext.REQUEST_SCOPE)

Thanx
 
Gaurav Sahni
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giju,

i think this is NOT the "correct" solution of the problem. JspContext class has an overridden method getAttribute(String name, int scope). Try using that, passing PageContext.REQUEST_SCOPE as the second paramter.

Regards,
Gaurav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic