简体   繁体   中英

Java Web App: Passing form parameters across multiple pages

what is the best practice or best way of passing form parameters from page to page in a flow? If I have a flow where a user enters data in a form and hits next and repeats this process until they get to an approval page, what ways could I approach this problem to make the retention of data as simple as possible over the flow?

I guess you could put all the information as you go in the session but could you get into memory issues if a lot of people are using your app and going through the flow at the same time?

您可以将数据存储到Cookie中或将它们存储到会话中 ,并在不同的网页之间访问它们。

HttpSession is your best bet if you want to track a "wizard" style data entry. Just seconding @Rachel's openion.

The server side component that handles your page submits ( such as Servlets) would have some code like:

public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException    
{
    HttpSession session = req.getSession();
    session.setAttribute("Variable1", request.getParameter("input1"));
    //and so on..

HttpSession Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user.

You may also put attributes in the request scope. They are accessed the same way from EL in your JSPs, but do not require a session. Depending on your situation, you may not wish to start sessions for every user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM