My website is successfully updating the database, printing all values, but for some reason the new page is not opening. The current page just keeps refreshing and I'm receiving a status of 0. Below is my code snippet:
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");
}
Even though "matched" gets printed below the window.open() function, indicating that values are being received, the new page is still not showing up. There are no errors in the console related to the page address. Could someone please point out what mistake I might be making? Any help is appreciated.
This portion relates to the 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();
}
}