File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 61082
    
  66

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: 61082
    
  66

 
 
subject: Trouble using pageContext in a simple tag handler