<% java.util.HashMap params = new java.util.HashMap(); params.put("a",a); params.put("b",b); pageContext.setAttribute("paramsName", params); %> now in actionclass paramsName=(HashMap)pageContext. .getAttribute("paramsName");
Now error is pageContext not resolved even though
I have imported
let me know the solution regards
posted 9 years ago
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.