• 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

servlet and SimpleTagSupport

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the classic Tag Handler works ..
pageContext.getAttribute("test",PageContext.REQUEST_SCOPE)

Thanx
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic