我正在尝试在我的项目中进行文件上传,但我面临着这个困难。当我运行它时,当我提交给 Server.jsp 时,我收到“访问被拒绝”脚本错误。
测试.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<iframe src = "fileselect.html" name = "attachfrm" width = 0 height=0></iframe>
<a id = "att" href = "javascript:document.attachfrm.clickattach('compose');" >AttachFile</a>
</BODY>
</HTML>
文件选择.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<title>Attach File</title>
</HEAD>
<script>
function atach(){
document.tattach.submit();
}
function clickattach(id){
document.tattach.F1.click();
}
</script>
<BODY>
<FORM ENCTYPE="multipart/form-data" ACTION=
"Server.jsp" METHOD=POST name="tattach">
<br><br><br>
<center><table border="2" >
<tr><td><b>Choose the file To Upload:</b>
</td>
<td>
<INPUT NAME="F1" id = "F1" TYPE="file" onChange="atach();"></td></tr>
<tr><td colspan="2">
<p align="right">
<INPUT TYPE="submit" VALUE="Attach" >
<INPUT TYPE="submit" VALUE="Cancel" onClick="window.close();">
</p>
</td></tr>
<table>
</center>
</FORM>
</BODY>
</HTML>
服务器.jsp
<%
System.out.println("------------got it-------------");
%>
注意(我得到这个工作gud的另一种方式):但是当我在Test.html中像这样更改文件点击时,这工作正常
<a id = "att" href = "javascript:document.attachfrm.tattach.F1.click();" >AttachFile</a>
但我需要执行我的第一种方法,因为我需要将参数从 Test.html 发送到 FileSelect.html 以获得某些功能。
如果我的第一种方法有误,请纠正我