How to pass a parameter to previous page?
I am working on a JSP project. I have a page that calls another JSP.
Now the problem is开发者_StackOverflow社区, how to pass or use a variable in the called JSP page in its calling page?
You can save the variable in the HTTPSession or ServletContext object.
And in the calling JSP page, use or check session attribute for the variable.
session.setAttribute(objectId, Object);
to set the variable.
session.getAttribute(objectId);
to get the variable.
I have a page that calls another jsp page
The problem lies here in this sentence.
Try to follow MVC. Use JSP
just for rendering the View, and Servlet
as a Controller.
Here, simple.souther.us, you find simple and awesome tutorials for newbies.
Your design should be
- take one input param on page1.jsp
- post it to some servlet , process it there, forward request to page1 jsp and pass param taken from page 1 as attribute
See Also
- why-business-logic-should-be-moved-out-of-jsp ?
精彩评论