سؤال

I have a single JSP page, which is used to upload files. This page has to be used in many different location in my application, but each time I use this page my action class for the form is different.

I am using Struts 2 and Hibernate. Could anyone please suggest on how to implement this.

Given below is my JSP code:

  <table width="100%" cellspacing="0" border="0" cellpadding="0">

<tr>
    <td colspan="3" align="left"><s:url
        action="" id="idfileValidate" escapeAmp="false"></s:url> <input
        type="button" class="btn"/></td>
</tr>

...............

<tr>
    <td colspan="3" align="left"><input type="button" class="btn"/><s:url
        action="" id="idfileUpload" escapeAmp="false"></s:url> <input
        type="button" class="btn" id="buttonUpload"/>
    </td>
</tr>
 </table>

The action in both the <s:url> tag will be different different calling locations.

هل كانت مفيدة؟

المحلول

You need to give action name in url as following

 <table width="100%" cellspacing="0" border="0" cellpadding="0">

<tr>
    <td colspan="3" align="left"><s:url
        action="fileValidate" id="idfileValidate" escapeAmp="false"></s:url> <input
        type="button" class="btn"/></td>
</tr>

...............

<tr>
    <td colspan="3" align="left"><input type="button" class="btn"/><s:url
        action="fileUpload" id="idfileUpload" escapeAmp="false"></s:url> <input
        type="button" class="btn" id="buttonUpload"/>
    </td>
</tr>
 </table>

You need to mapped that action in struts.xml as following

<action name="fileValidate" 
            class="com.action.struts2.validatefileaction" >

<action name="fileupload" 
            class="com.action.struts2.fileupload" >

Try this

نصائح أخرى

The only action name is variable in your JSP. Create a field in each action class or in the base class as

String actionName;
//getter and setter

then use this in JSP

<tr>
    <td colspan="3" align="left"><s:url
        action="%{actionName}" id="id%{actionName}" escapeAmp="false"></s:url> <input
        type="button" class="btn"/></td>
</tr>

it will dynamically substitute the action name for each action returning a result with this JSP.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top