1

我有一个带有文件上传选项的网络表单。我使用multipart/form-data了 enctype 和 post 方法来提交表单。在服务器端,我使用 struts2 动作类。请在下面找到代码。

JSP:

<s:form action="createAdvertisement" id="heRegistration" theme="simple"
    name="advertisementForm" validate="true" method="post"
    enctype="multipart/form-data">
    <s:hidden name="lastAccessTime" id="lastAccessTime"></s:hidden>

    <table width="520px" border="0" cellspacing="0" cellpadding="0"
        class="formStyles">
        <tr height="35">
            <td><s:text name="global.Advertisment" /><span
                class="important"> *</span></td>
            <td>:</td>
            <td><input type="file" name="imageUpload"> <span
                id="vMsg"
                style="position: relative; top: -26px; width: 360px; height: 22px; color: red;">
            </span></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td><span class="tableErrorSpan"> <s:fielderror
                        cssStyle="font-size:10px;" fieldName="imageUpload"></s:fielderror></span>
            </td>
        </tr>

        <tr>
            <td></td>
            <td></td>
            <td id="removeButton"><span id="errAdd" class="tableErrorSpan"></span></td>
        </tr>

        <tr height="35">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td><input type="submit" class="btn btnIEfix"
                value="<s:text name="button.save"/>"
                name="action:createAdvertisement" alt="Save"> <input
                type="button" name="cancel" class="btn btnIEfix btnInline"
                onclick="location.href='cancelAdvertisement.action'"
                value="<s:text name="button.cancel"/>" /></td>
        </tr>
    </table>
</s:form>

Struts 配置:

<action name="createAdvertisement" method="createAdvertisement"
        class="categoryAdvertisementsAction"> 
    <interceptor-ref name="fileUploadStack" /> 
    <result name="success">jsp/admin/addSuccess.jsp</result> 
    <result name="input">jsp/admin/createAdvertisments.jsp</result> 
</action>

接受输入文件的动作类代码行:

private File imageUpload;

final BufferedImage originalImage = ImageIO.read(imageUpload);

该表单在某些 PC 中提交,但在某些 PC 中未提交。我需要知道为什么会发生这种情况以及 enctype 是否对硬件有任何依赖。

更新

@Konza:请在下面找到原始 html。

<form enctype="multipart/form-data" method="post" action="createAdvertisement.action" name="advertisementForm" id="heRegistration">
  <table width="95%" cellspacing="0" cellpadding="0" border="0" class="formStyles">
      <tbody>
        <tr height="35">
            <td>Advertisement<span class="important"> *</span></td>
            <td>:</td>
            <td><input type="file" name="imageUpload" id="filestyle-0" style="position: fixed; left: -500px;"><div style="display: inline;" class="bootstrap-filestyle"><input type="text" disabled="" class="input-large"> <label class="btn" for="filestyle-0"><i class="icon-folder-open"></i> <span>Browse</span></label></div>
                    <span style="position: relative; top: -26px; width: 360px; height: 22px; color: red;" id="vMsg">
                    </span>

            </td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td>
                <span class="tableErrorSpan">
                        </span>
            </td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td id="removeButton"><span class="tableErrorSpan" id="errAdd"></span></td>
        </tr>

        <tr height="35">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>
            <input type="submit" alt="Save" name="action:createAdvertisement" value="Save" class="btn btnIEfix">
             <input type="button" value="Cancel" onclick="location.href='cancelAdvertisement.action'" class="btn btnIEfix btnInline" name="cancel">
              </td>
        </tr>
    </tbody></table>
</form>

@Andrea Ligios:所有 PC 都在代理后面。

@Aleksandr M:当我使用eclipse调试代码时,表单提交没有到达相关的struts动作类,所以服务器端验证不起作用。

4

0 回答 0