当前位置: 代码迷 >> Web前端 >> struts2 action 运作完不跳转
  详细解决方案

struts2 action 运作完不跳转

热度:158   发布时间:2012-08-26 16:48:06.0
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;

?}

?

  相关解决方案