Lets say a servlet text.java returns an html content to a jsp page index.jsp.
IN index.jsp
<button onclick="location.href='text'">CLICK</button>
IN text.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<b>HELLO</b>");
} finally {
out.close();
}
}
Now we say that servlet responds to the web browser’s request, then after clicking on the button why in the url instead of the jsp page the name of the servlet is there and the control is not returned to the jsp page.
Is that only possible with ajax (formelement.innerHTML= ob.responseText()) ?
//where var ob = new XMLHttpRequest();
you can proceed like this…
and in jsp just get the result by :