multiple struts actions on single form not working [duplicate]

半腔热情 提交于 2019-12-08 06:42:49

问题


I am trying to call an action on submit button but it is not working.

index.jsp

<s:form method="post" enctype="multipart/form-data">
    <s:file label="Upload Matrix.csv file:" name="file"></s:file>
    <s:submit value="Upload" action="uploadFile" cssClass="btn btn-info"></s:submit>
    <s:submit value="Update" action="fileData" cssClass="btn btn-primary" />
    <s:submit value="Show" action="sessionMatrix" cssClass="btn btn-primary"/>
</s:form>

struts.xml

<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.ui.theme" value="bootstrap" />

    <package name="default" namespace="/" extends="json-default,struts-default">

        <!-- cities populate -->
        <action name="ajaxAction" class="com.action.PopulateCities">
            <result type="json">/sessionMatrix.jsp</result>
        </action>

        <!-- JTable populate -->
        <action name="*Action" class="com.action.SessionRecordsAction"
            method="{1}">
            <result type="json">/sessionMatrix.jsp</result>
        </action>
        <action name="getJSONResult" class="com.action.SessionRecordsAction"
            method="list">
            <result type="json" />
        </action>

        <!-- to upload csvfile data into database -->
        <action name="fileData" class="com.util.UploadData">
            <result name="success">/sessionMatrix.jsp</result>
            <result name="error">/error.jsp</result>
        </action>

        <!-- to display data into table i.e ResultSet implementation -->
        <action name="sessionMatrix" class="com.action.SessMatrixAction">
            <result name="success">/exportSession.jsp</result>
            <result name="error">/error.jsp</result>
        </action>

        <!-- upload file -->
        <action name="uploadFile" class="com.action.FileUpload">
            <interceptor-ref name="defaultStack">
                <param name="fileUpload.maximumSize">10485760</param>
            </interceptor-ref>
            <result name="success">/dashboard.jsp</result>
            <result name="error">/error.jsp</result>
            <result name="input">/dashboard.jsp</result>
        </action>
    </package>
</struts>

What I am doing is calling execute method of of each action class I even tried by mentioning method attribute in action tag as well as <s:submit> tag.


回答1:


Since Struts 2.3.15.3, you need to explicitly enable the action: suffix with:

<constant name="struts.mapper.action.prefix.enabled" value="true"/>

You may also be interested in reading about the ways to call different actions from a form.




回答2:


You have missed an action attribute in <s:form> tag. Use action attribute in your code as

    <s:form method="post" enctype="multipart/form-data" action="actionName">
  ....
</s:form>


来源:https://stackoverflow.com/questions/25907243/multiple-struts-actions-on-single-form-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!