除了 RequestDispatcher 之外我还必须使用什么?
我正在从 jsp 页面添加一些数据(Add.jsp
)。添加数据后,当我单击“提交”按钮时,我必须显示相应表的视图页面。
在这里,如果目前我正在向表中插入 3 行(来自我的 Add.jsp
),如果表包含已包含 2 行,我已在我的 veiw 页面中显示这 5 行(view .jap
)。
为此,我
if ("Submit".equals(request.getParameter("button"))) {
//geting page values from request.getParameter(name);
String message = obj.addDetails(beanObj);//this method returns string value after successfully inserting
if(message.equals("Added"))
{
RequestDispatcher rd = request.getRequestDispatcher("View.jsp");
rd.forward(request, response);
}
}
在浏览器中编写了类似于 Add.jsp
的代码,我得到了 View.jsp
。但在 url 中它只是 Add.jsp
(观察这一点)。
问题:我的问题是,当我在浏览器上单击刷新按钮(在当前页面中显示 veiw.jsp
)时,我在页面字段中提交的数据是什么(Add.jsp
) >) 我再次插入数据库并在我的页面中显示总共 8 行。
请给我代码,除了 RequstDiapatcher
之外我还需要写什么?
i am adding some data from my jsp page(Add.jsp
). after adding that data when i click on submit
button i have to show the view page of the corresponding table.
Here if presently i am inserting 3 row(from my Add.jsp
) to the table, if table contains already contains 2 rows, i have show those enitre 5 row in my veiw page(view.jap
).
for that i am written code like in Add.jsp
if ("Submit".equals(request.getParameter("button"))) {
//geting page values from request.getParameter(name);
String message = obj.addDetails(beanObj);//this method returns string value after successfully inserting
if(message.equals("Added"))
{
RequestDispatcher rd = request.getRequestDispatcher("View.jsp");
rd.forward(request, response);
}
}
in my browser i am getting View.jsp
. but in url it was Add.jsp
only(observe that).
Question: My problem was when i clicking on refresh button (in current page that show veiw.jsp
) on browser what ever the data iam submitting in field on page(Add.jsp
) i was again inserting in database and showing like totaly 8 row in my page.
Please give me the code for, what i have to write apart from RequstDiapatcher
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用response.sendRedirect(“View.jsp”)。
如果您需要显示一些消息(例如“记录已成功插入”),则需要执行以下操作之一:
response.sendRedirect("View.jsp?message=success")
顺便说一句,您最好将处理逻辑放在 servlet 而不是 JSP 中(这是一种视图技术)
Use
response.sendRedirect("View.jsp")
.If you need to display some message (like "Records inserted successfully), you will need one of the following:
response.sendRedirect("View.jsp?message=success")
And by the way, you'd better place your processing logic in a servlet rather than a JSP (which is a view technology)