新页面未加载到html中

时间:2017-03-27 00:27:33

标签: javascript ajax servlets

通过我的网页我正在更新我的数据库,一旦数据库更新,将打开一个新页面。一切都在发生,即数据库我正在更新,所有值都被打印等但新页面没有打开,同一页面正在刷新。我的状态也是0.这是我的代码。

      try{
                console.log("here1 "+email);
                get1.open("GET","/Livie_project1/Check2?id="+email+"&id1="+parms["name"][0],true);
                }catch(Exception )
                {
                    console.log("error11");
                }
                get1.onreadystatechange = function() {
                console.log(this.readyState+" get1 "+this.status);
                if (this.readyState === 4) {
                window.open("/Livie_project1/index.html?name="+email,"_self");
                console.log("matched");
                var JSONtopicobject=eval( "("+this.responseText + ")" );
                var t=JSONtopicobject.topic.name;
                var t2=JSONtopicobject.topic.name1;
                console.log(t2+" "+t);
                }};
            try{
                get1.send(null);
                }catch(Exception)
                {
                    console.log("erro12");
                }

如代码中所示,所有值都被打印,即匹配正在打印,它位于window.open()函数的正下方。页面的地址是正确的,因为我在控制台中没有收到任何错误。 请让我知道我在做什么错误。请帮忙。

这是servlet部分

          public class Check2 extends HttpServlet {
           String pwd;
           @Override
           protected void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {      
            String name=req.getParameter("id"); 
            String name1=req.getParameter("id1"); 
            Connection con=null;        
            Statement stmt=null;        
            PrintWriter out=res.getWriter();        

            try{
                //get a connection
                con=DriverManager.getConnection("jdbc:mysql://localhost/login","root","ATul1996@@");
               //Execute a query
                int count=0;
                stmt=con.createStatement();    
                String query ="update login set pwd="+"\""+name+"\""+" where email = "+"\""+name1+"\"" ;
                int j=stmt.executeUpdate(query);
            }        
            catch(SQLException e)        
                {
                    out.println(e);               
                }

            res.setContentType("text/html");
            StringBuffer  returndata =new StringBuffer("{\"topic\":{");
            returndata.append("\"name\": ");
            returndata.append("\"");
            returndata.append(name);
            returndata.append("\"");
            returndata.append(",");
            returndata.append("\"name1\": ");
            returndata.append("\"");
            returndata.append(name1);
            returndata.append("\"");
            returndata.append("}}");
            res.getWriter().write(returndata.toString());
            res.getWriter().flush();
            res.getWriter().close();
        }


    }

1 个答案:

答案 0 :(得分:0)

您的代码中有错误

  window.open("/Livie_project1/index.html.html?name="+email,"_self");

应阅读:

  window.open("/Livie_project1/index.html.html?name="+email,"_blank");

您实际上并不需要指定它,因为默认为_blank。

设置为" _self"它将指示URL在当前窗口中执行操作。