Hi I am working on a webbased application with JSPs and servlets. I have a page which has a button in it. I have written some javascript to pop-up a small window when the button is clicked and also it invokes the doPost method. The code is something like this —
]
"<form name='downloadFrm1' method='post' action='S2VServlet'
.. ..
"<input name='submitBtn' type='submit' value='Download Files With Warnings' onClick="+popup+">\n"+
"</form><BR></div><p><BR></p> \n";
However, I invoke the doPost method only to do some internal work. I don’t want the parent page to be redirected anywhere. But what is happening is that when I click on the button the small popup window appears but the parent page also moves to a blank page. How can I make the parent page stay as is and not get redirected ? The code for doPost is something like ths–
public void doPost(HttpServletRequest p_req, HttpServletResponse p_res) throws IOException, ServletException {
try {
String downloadKey = p_req.getParameter(DOWNLOAD_KEY_ELEMENT);
....
if (//put my condition)) {
//just set some internal value and return
....
return;
}
You can’t do it without ajax (javascript). The standard request/response cycle requires a change in the page.
Take a look at jQuery. You can do
$.post("S2VServlet", {param:param})which will execute in the background.