日期:2014-05-20  浏览次数:20703 次

紧急求助,写一个可以上传附件的jsp代码,采用ajax无刷新上传,上传没问题,但是提交其他信息得到的是null值
下面是相应的代码,不知道有没有人遇到过,麻烦告知一下解决办法:

提交页面:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>upload</title>
<script language="javascript" type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function(){

var options = { 
url:'/uploadFile/upload.action',
type:'POST', 
dataType:'script',
success: function(){alert("ok!");} 
};
$('#form1').ajaxForm(options);

$("#upload").click(function(){
$('#form1').submit();
});

$("#tijiao").click(function(){
document.form1.action = "receive.jsp";
document.form1.submit();
});
});
</script>
</head>
<body>
<form action="receive.jsp" name="form1" id="form1" method=post>
<table width="500" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="100">名  字:</td>
<td colspan="2"><input type="text" name="name" id="name" value="" /></td>
</tr>
<tr>
<td width="100">本地选择:</td>
<td width="280"><input type="file" name="selPicture" style="width: 250px; height: 23px; font-size: 16px"></td>
<td width="120"><input type="button" name="upload" id="upload" value="上传" style="width: 70px; height: 25px"></td>
</tr>
<tr><td colspan="3"><input type="button" value="提交" name="tijiao" id="tijiao"/></td></tr>
</table> 
</form>
</body>
</html>

接收页面:

<%@ page language="java" import="java.util.*,com.jspsmart.upload.*,java.io.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>receive file</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
 %>
姓名:<%=name %>

</body>
</html>

上传采用的是smartupload插件,文件上传没有问题,但是得到的姓名为null

------解决方案--------------------
我记得type好象是要设为get的


------解决方案--------------------
我只用过 ajaxfileupload 插件,这个插件还有一个小bug