Two Laptop Bag
The moose likes Struts and the fly likes pageContext problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "pageContext problem" Watch "pageContext problem" New topic

pageContext problem

arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
java.util.HashMap params = new java.util.HashMap();
pageContext.setAttribute("paramsName", params);
now in actionclass

Now error is pageContext not resolved even though

I have imported

import javax.servlet.jsp.*;

let me know the solution
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In a JSP, the pageContext variable is automatically defined for you. In an Action class it is not. That's why you're getting the compile error.

You have at least two more problems, though.

1.A PageContext object was intended for use only in a JSP, so there isn't really a way to instantiate one in an action class. It's an abstract class and its App Server specific subclass must be instantiated by the App Server.

2.Even if there were a way to instantiate a PageContext in your Action class, you still couldn't use it to pass data from a JSP to an Action class. The scope of a PageContext object is, as the name implies, a single JSP page. Request scope won't work either. When the form is submitted, a different request is active than the one that created the JSP page.

I'd suggest you have your JSP put the HashMap in the session and have your Action class retrieve it from the session. Another alternative would be to create hidden fields for each item in the HashMap and then retrieve them as parameters from the request object in your action class.

Consultant, Sima Solutions
I agree. Here's the link:
subject: pageContext problem
It's not a secret anymore!