Spring MVC - передача переменных с одной страницы на другую

Мне нужна помощь. Я работаю над проектом, где у меня есть несколько страниц и несколько форм; каждая страница имеет одну форму. Мне просто нужно иметь возможность передавать значения из одного JSP в другой. Что я должен делать?

Я новичок в Spring MVC. Я использую весну 2.5.6.

Вот мой дизайн:

formPage1.jsp - & gt; Контроллер1 - & gt; formPage2a.jsp - & gt; Контроллеру 2 требуется val из pg1 & amp; pg2a. formPage1.jsp - & gt; Контроллер1 - & gt; formPage2b.jsp - & gt; Контроллеру 3 требуется val из pg1 & amp; pg2b. formPage1.jsp - & gt; Контроллер1 - & gt; formPage2c.jsp - & gt; Контроллеру 4 требуется val из pg1 & amp; pg2c.

Как вы можете видеть выше, formPage1.jsp может загружать либо formPage2a, formPage2b или formPage2c. На основе входных данных, предоставленных в formPage1.jsp, он отправляется в контроллер (который является расширением SimpleFormController), и контроллер получает значения, введенные объектом user = command.

Я хочу иметь возможность использовать эти значения объекта команды либо в formPage2a, formPage2b или formPage2c, когда они передаются на другой контроллер.

вот текущий код:

formPage1.jsp:
<form:form method="post" commandName="gainLossRequest">
            <form:errors path="*" cssClass="error"/>
            <table>
                <tr>
                    <td>
                        <table>
                            <tr>
                                <td><h4>Choose Client</h4></td>
                                <td style="font-size: medium; font-family: Arial, bold; color: red">*</td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <form:select path="client">
                            <form:option value="none" label="Select" />
                            <form:option value="abc" label="abc" />
                            <form:option value="def" label="def" />
                            <form:option value="xyz" label="xyz" />
                        </form:select>
                    </td>
                </tr>
<tr>
                    <td colspan="2">
                        <input type="reset" value="Reset" />
                        <input type="submit" value="Next" />
                    </td>
                </tr>
            </table>
            </form:form>
Controller1.java
public class TestController extends SimpleFormController {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    public TestController() {
        logger.info("entering TestController.constructor..");
        setCommandClass(UserPreference.class);
        setCommandName("userPreference");
    }

    public ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws ServletException {
        logger.info("entering TestController.onSubmit all..");

        UserPreference userPreference = (UserPreference) command;

        ModelAndView view = null;

        if ("abc".equals(userPreference.getClient())) {
            GainLossRequest gainLossRequest = new GainLossRequest(userPreference);
            view = new ModelAndView("redirect:/test/gainLossRequest.htm",
                    "gainLossRequest", gainLossRequest);
                } else if ("def".equals(userPreference.getClient())) {
            IncomingPositionsRequest incomingPositionsRequest = new IncomingPositionsRequest();
            view = new ModelAndView(
                    "redirect:/test/incomingPositionsRequest.htm",
                    "incomingPositionsRequest", incomingPositionsRequest);
        } else if ("xyz".equals(userPreference
                .getClient())) {
            TaxStrategyRequest taxStrategyRequest = new TaxStrategyRequest();
            view = new ModelAndView("redirect:/test/taxStrategyRequest.htm",
                    "taxStrategyRequest", taxStrategyRequest);
        }
        }
}
formPage2a.jsp
<form:form method="post" commandName="gainLossRequest">
            <form:errors path="*" cssClass="error"/>
            <table style="width: 60%">
                <tr>
                     <td>Account Number (s):</td>
                     <td style="font-size: medium; font-family: Arial, bold; color: red">*</td>
                </tr>
                <tr>
                    <td>
                        User Chosen Client: 
                    </td>
                    <td>
                        <c:out value="${gainLossRequest.client}"/>
                    </td>
                </tr>
                                <tr colspan="2">
                                        <td>
                        <input type="reset" value="Reset" />
                        <input type="submit" value="Submit" />
                    </td>
                </tr>
dispatcher servlet config
<!-- setupNew.jsp is the first jsp --> 

<bean name="/test/setupNew.htm" class="chimeraweb.web.TestController">
        <property name="sessionForm" value="true"/>
        <property name="commandName" value="userPreference"/>
        <property name="commandClass" value="chimeraweb.service.UserPreference"/>
        <property name="validator">
            <bean class="chimeraweb.service.UserPreferenceValidator"/>
        </property>
        <property name="formView" value="/test/setupNew"/>
    </bean>


<!-- gainLossRequest.jsp is the 2nd jsp where I want to display the values captured in the first jsp page -->

    <bean name="/test/gainLossRequest.htm" class="chimeraweb.web.SimpleGainLossController">
        <property name="sessionForm" value="true"/>
        <property name="commandName" value="gainLossRequest"/>
        <property name="commandClass" value="chimeraweb.service.GainLossRequest"/>
        <property name="validator">
            <bean class="chimeraweb.service.GainLossValidator"/>
        </property>
        <property name="formView" value="/test/gainLossRequest"/>
    </bean>

Пожалуйста помоги!!

Ответы на вопрос(3)

Ваш ответ на вопрос