In blog-edit.html, jQuery was used to send a server-side send request (Java servlet).
$("#btn").click(function() { $.post("/blog/handler",{"content":$('#textarea').val()}, function(data){ alert("Data Loaded: " + data); if(data.toString().length>1){ alert("Saved!") }else{ alert("Failed!") } })
On the server side:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String content = request.getParameter("content"); System.out.println(content); response.sendRedirect("/blog/list"); return; }
I saw that the server side is printing content from html, and a warning window appears to say "Saved!". But the redirect function does not work
After searching, I have no choice but to use jquery to redirect:
if(data.toString().length>1){ alert("Saved!") window.location.replace("/blog/list") }
it works but that is not what i want
please, help
source share