使用 doPost 但仍停留在同一页面
您好,我正在开发一个带有 JSP 和 servlet 的基于 Web 的应用程序。我有一个页面,其中有一个按钮。我编写了一些 JavaScript 来在单击按钮时弹出一个小窗口,并且它还会调用 doPost 方法。代码是这样的——
]
"<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";
但是,我调用 doPost 方法只是为了做一些内部工作。我不希望父页面重定向到任何地方。但发生的情况是,当我单击按钮时,会出现小弹出窗口,但父页面也会移动到空白页面。如何使父页面保持原样而不被重定向? doPost 的代码是这样的——
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有ajax (javascript),你就无法做到这一点。标准请求/响应周期需要更改页面。
看一下 jQuery。您可以执行
$.post("S2VServlet", {param:param})
,它将在后台执行。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.我认为你可以通过 doGet 来结束你的 doPost 方法。这样做会“重复”该页面,但用户认为他/她没有移动。
I think you can end your doPost method doing doGet. Doing so will "repeat" the page, but the user thinks he/she has not moved.