问题描述:

I have login and calculation JSP pages. Calculation page contains list, which needs initialized action object. Here is login.xml

<struts>

<package name="default" extends="struts-default">

<action name="*Action" class="com.task.action.{1}Action">

<result name="success">/calculation.jsp</result>

<result name="input">/login.jsp</result>

</action>

</package>

</struts>

calculation.jsp:

<s:form action="CalculationAction">

<s:select label="Types"

list="calculationTypes"

name="calculationType" value="getDefaultCalculationType"/>

<s:submit />

</s:form>

After executing LoginAction class, i got "success" and move to calculation.jsp. Problem is CalculationAction is not created, and list in jsp can't initialize. If i call http://localhost:8082/Task/CalculationAction.action , jsp page is creating correctly.

I also tried to make references in login page and it works too.

<s:url id="calculationUrl" action="CalculationAction"> </s:url>

<div class="tab-wrapper">

<a href="login.jsp">Login Page</a>

<s:a href="%{calculationUrl}">Calculation Page</s:a>

</div>

How to make the program working correctly after executing LoginAction?

网友答案:

Add one more result for LogingAction to redirect to CalculationAction, and return this result instead of "success" in the LogingAction.

<action name="*Action" class="com.task.action.{1}Action">
    <result name="success">/calculation.jsp</result>
    <result name="input">/login.jsp</result>
    <result name="successfulLogin" type="redirectAction">CalculationAction</result>
</action>

The CalculationAction on "success" should return a calculation.jsp and calculation action will be in the value stack, so you can get calculationTypes initialized when the action was executed.

相关阅读:
Top