我有一个JSP页面,用于上传文件。此页面必须在我的应用程序中的许多不同位置使用,但每次我使用此页面时,表单的操作类都是不同的。
我正在使用 Struts 2 和 Hibernate。任何人都可以建议如何实现这一点。
下面给出的是我的 JSP 代码:
<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>
<s:url>
中的操作不同的调用位置,标签会有所不同。
最佳答案
您需要在网址中给出操作名称,如下所示
<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>
您需要在 struts.xml 中映射该操作,如下所示
<action name="fileValidate"
class="com.action.struts2.validatefileaction" >
<action name="fileupload"
class="com.action.struts2.fileupload" >
试试这个
关于java - 具有不同 Action 类的单个 JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23336708/