用window.location.href为什么跳转不到servlet里??

问题描述

用window.location.href为什么跳转不到servlet里??

删除
function empDelete(){

            var obj = document.getElementsByName("del_flag");

            var arr = new Array ();
            var obj = document.getElementsByName("del_flag");

            for (var i = 0;i<obj.length;i++) {
               if (obj[i].checked) {
                    arr.push(obj[i].value);

               }
            }
            //alert(arr);

            if (arr.length == 0) {
                   alert("请选择要删除的记录!");

            } else {    

                window.location.href = "EmployeeDeleteServlet?cb="+arr;
                alert(arr);
            }

    }

servlet里:
String[] df= request.getParameterValues("cb");

        for(int j = 0;j<df.length;j++){
            System.out.println(df[j]);
        }

        Connection conn = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
        int result = 0;

        try {
            conn = DBUtil.getConn("employee");
            if(df != null && df.length>0){
                for(int i = 0;i<df.length;i++){
                    pst = DBUtil.getPst(conn,"delete from EmpInfo where num = ?");
                    pst.setString(1, df[i]);
                    result = pst.executeUpdate();
                }
                if(result > 0){
                    response.sendRedirect("employee_list.jsp");
                }else{
                    request.setAttribute("errmsg", "删除数据失败");
                    request.getRequestDispatcher("error.jsp").forward(request, response);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

}

解决方案

在跳转地址EmployeeDeleteServlet前面加上./ 这样 ./EmployeeDeleteServlet?cb

解决方案二:

window.location window.location.href 跳转url区别

解决方案三:

window.location.href = "EmployeeDeleteServlet?cb="+arr;
在这上面打出一个alert语句。输出"EmployeeDeleteServlet?cb="+arr这一段,看看是不是地址错了

时间: 2024-08-25 06:13:07

用window.location.href为什么跳转不到servlet里??的相关文章

javascript- window.location.href页面跳转

问题描述 window.location.href页面跳转 解决方案 "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一层页面跳转 "top.location.href"是最外层的页面跳转 举例说明: 如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写 "windo

IE6浏览器中window.location.href无效的解决方法_javascript技巧

本文实例讲述了IE6浏览器中window.location.href无效的解决方法.分享给大家供大家参考.具体方法如下: window.location.href是js中跳转功能,很多人在ie6中都会发现window.location.href不能跳转了,下面我给大家来介绍一下其原因与解决方法. 问题代码如下: 复制代码 代码如下: <a href="javascript:void(0);" onclick="javascript:test();">点击

window.location.href IE下跳转失效的解决方法

 这篇文章主要介绍了window.location.href IE下跳转失效的解决方法,需要的朋友可以参考下 代码如下: <a href="javascript:void(0)" >GoNext</a>  $("a").click(function(){  window.location.href = "xxx.html";  })    代码如上,在IE下,特别是在IE6中,点击超链接之后,浏览器并没有发生跳转行为. 

javascript-js window.location.href 跳转显示404错误,但是路径是对的

问题描述 js window.location.href 跳转显示404错误,但是路径是对的 地址是对的,但是服务器却显示404错误, 要手动刷新一下,页面才显示出来. 这是为什么啊 用C#后台写的:Response.Write("window.location.href='SHPage.html?sName=" + jumpStore + "'"); 别说什么地址错误,页面找不到. 如果是这样的话,网址不变,为什么网页重新刷新就正常显示了.这就不是地址错误了吧,地

window.location.href IE下跳转失效的解决方法_javascript技巧

复制代码 代码如下: <a href="javascript:void(0)" >GoNext</a> $("a").click(function(){ window.location.href = "xxx.html"; }) 代码如上,在IE下,特别是在IE6中,点击超链接之后,浏览器并没有发生跳转行为. 原因可能是因为在href中的javascript:void(0)阻止的事件行为,解决方法如下: 1.在onclic

javascript window.location.href 跳转问题

问题描述 javascript window.location.href 跳转问题 请先看代码片段: if(1>0){ window.location.href="a.html"; } if(1<0){ window.location.href="b.html"; }else{ window.location.href="c.html"; } 为什么不跳转 a.html,反而跳转到了c.html 解决方案 http://www.jb5

window.location.href跳转问题2

"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一层页面跳转 "top.location.href"是最外层的页面跳转 举例说明: 如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写 "window.location.href"."locatio

window.location.href = window.location.href 跳转无反应 a超链接onclick事件写法_javascript技巧

错误写法 , 主要是在 href="#"这里 复制代码 代码如下: 错误写法 , 主要是在 href="#"这里 脚本如下 复制代码 代码如下: if (data == "发送成功") {                    alert(data);                    window.location.href = window.location.href;                } 正确的写法  href 后面跟一个

javascript-关于js,jquery问题,return false与window.location.href

问题描述 关于js,jquery问题,return false与window.location.href 我给每个 <a> 都加了个window.location.href,然后给一个a标签返回return false,但是不能取消 还是跳转了? $("#remove").click(function(){ var $tr = $(this).parent().parent(); var title = $.trim($tr.find("td:first"