在线急等 jquery ajax 中怎么提交里面的Excel到Action里面解析
<form id="listForm1" name="listForm1" method="post" enctype="multipart/form-data">
<br>
<table class="tviewbody" cellSpacing="1" cellPadding="0" width="100%" border="0">
<tr>
<td class="tabletxt" colspan="2">
<input name="file" type="file" id="file" value="" contenteditable="false">
<font color="red">* </font>
</td>
<td class="tabletxt" colspan="">
<input type="button" id="imp" name="button1" value="导入" onclick="">
<input type="button" id="con" name="button2" value="取消" onclick="javascript:cancel();">
</td>
</tr>
</table>
<br>
</form>
以上是JSP页面的form
下面是 jQuery
jQuery.noConflict(); //将变量$的控制权让渡给prototype.js
jQuery(function(){
jQuery("#imp").click(function (){
var file = jQuery("#file").val();
if(file==""){
alert("导入文件不能为空");
return ;
}
jQuery.ajax({
type:"post",
url:"<%=request.getContextPath()%>/gd/getgExcel.do",
enctype:"multipart/form-data",
contentType:"application/x-www-form-urlencoded;charset=GBK",
dataType:"json",
data:jQuery("#listForm1"),
success:function(data,status){
alert('成功');
}
});
});
})
后台是 struts1
public ActionForward getgExcel(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response,RequestHashNew reh) throws Exception {
response.setContentType("text/html;charset=GBK;");
PrintWriter out = reh.getRes().getWriter();
try {
FileForm fileForm=(FileForm) form;
FormFile file = fileForm.getFile();
fileForm一直是null 求大神帮忙