如何将表单输入文件放在另一个表单中?

时间:2019-11-09 07:01:31

标签: html struts2

我有一个注册表格,我也想输入表格输入文件以选择用户要导入的文件。

当我将文件输入表单放入注册表单时,它显示了表单的无效位置,并且在提交时调用了两个表单动作。

这是我的代码:-

<%@ taglib uri="/struts-tags"  prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Upload File Page</title>
</head>
<body>
<h3>Select File to Upload</h3>
<form action="RegisterForm">

    <s:form action="UploadFile" method="post" enctype="multipart/form-data">
    <s:file label="File" name="file"></s:file>
    <s:submit value="Upload"></s:submit>

    Name :<input type="text" name="name">
    Age :<input type="text" name="age">
    Email :<input type="text" name="email">
    <input type="submit" value="Submit"/>
</s:form>
</form>

</body>
</html>

这是我的struts.xml:-

<action name="UploadFile" class="com.shivsashi.struts.actions.UploadFileAction">
            <param name="filesPath">myfiles</param>
            <result name="success">/UploadFileSuccess.jsp</result>
            <result name="input">/UploadFile.jsp</result>

            <interceptor-ref name="defaultStack">
                <param name="fileUpload.maximumSize">10485760</param>
                <param name="fileUpload.allowedTypes">text/plain,image/jpeg</param>
            </interceptor-ref>
</action>

<action name="RegisterForm" class="com.journaldev.struts2.actions.Registeration">
            <result name="success">/RegisterSuccess.jsp</result>
</action>

0 个答案:

没有答案