- Java code
<logic:notEmpty name="adminInfoForm" property="notVerifiedProductionList"> <logic:iterate id="production" name="adminInfoForm" property="notVerifiedProductionList" indexId="index"> <bean:write name="production" property="title"/> <bean:write name="production" property="authors"/> <bean:write name="production" property="time" format="yyyy-MM-dd"/> <bean:write name="production" property="place"/> <html:form action="/adminInfo" method="post" enctype="multipart/form-data" onsubmit="javascript:return check();"> <html:hidden property="method" value="uploadFile"/> <input type="hidden" name="productionId" value="<bean:write name='production' property='id'/>"/> 上传文件:<html:file property="myFile"></html:file> <input type="submit" value="上传"/> </html:form> </logic:iterate></logic:notEmpty>
在这个<html:form/>里面有个<html:file/>为了验证必须上传pdf文件,我写了下面一段Javascript
- JScript code
function check(){ var len = document.all.myFile.value.length; var str = document.all.myFile.value; var xx = str.substr(str.lastIndexOf("."),len); if(xx == ".pdf"){ return true; } else{ alert("必须上传PDF格式文件"); return false ; }}
由于JSP页面中有logic:iterate,它会列出需要上传文件的所有框框,因而会有好多个<html:file property="myFile"/>,因而上面的JS验证就不能生效了,因为有好多个myFile,名字都一样,我想问的是该如何验证myFile必须为pdf格式?
(这里不能采纳多个同时上传的方法,因为每个pdf文件对应相对应的对象)
------解决方案--------------------
需要验证什么啊 楼主是要验证文件是否是指定的后缀?
为什么不在类里面写?