struts2 不跳转

场景:struts2 action 运作完不跳转

struts2 action 运行完不跳转

我的目的是点"导入"按钮,执行名为"test.do"的action,但就算action里return null;他还是会跳转,其实要执行action只要把action的地址传给服务器就OK了。

用jQuery的jQuery.ajax 方法,能完全不跳转,

不加Math.random()没反应,在action拿filePath的地方再去掉那个随即数就可以了,

没参数也加上随机   $.ajax({url:"temp.do?rnd="+Math.random()});

jsp

<script>

function do_import() {
var rnd=Math.random().toString().substring(3,13);
 var filePath = document.getElementById("filePath").value;
 if (filePath == "") {
  alert("请选择文件");
 } else {
  $.ajax({url:"test.do?filePath="+rnd+filePath});
 }}

</script>

<input type="file" name="filePath" id="filePath" />

<input type="button" value="导入" onclick="do_import()" />

 

action

 @Override
 public String doAction(HttpServletRequest request,
   HttpServletResponse response) throws Exception {

   importRecInfoLogic.saveAttRecInfo(filePath.substring(10));
  return null;

 }