jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Trouble using pageContext in a simple tag handler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Trouble using pageContext in a simple tag handler" Watch "Trouble using pageContext in a simple tag handler" New topic
Author

Trouble using pageContext in a simple tag handler

Nirvikalp Rao
Greenhorn

Joined: Feb 14, 2012
Posts: 27

I wrote a simple tag handler class (adviser.java), which extends SimpleTagSupport class. In it's public void doTag() method,
i tried to use JspContext object to access request parameters. Because I have read that method getJspContext() returns
an object, which is actually a pageContext.
The code for my handler class is as follows:



But while compiling this file I am getting a compile time error saying:



What is wrong with my code.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Cast the JSP context to a PageContext.

The sane Java rules apply everywhere. If you have a reference to the superclass of a subclass, you must up-cast to use the methods of the subclass.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nirvikalp Rao
Greenhorn

Joined: Feb 14, 2012
Posts: 27

Thanks Bear, After casting ,it's working fine.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Trouble using pageContext in a simple tag handler