使用Servlet类将调用的JSP重定向到其自身 [英] Redirecting a calling JSP to itself using Servlet Class

查看:55
本文介绍了使用Servlet类将调用的JSP重定向到其自身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图借助Java servlet类将JSP请求返回到调用页面. 这意味着,在JSP页面上添加注释后,在将请求对象发送到servlet之后,注释也会重新出现在页面上. 这是jsp形式:

I am trying to return a JSP request back to the calling Page with the help of a Java servlet class. This means that after adding a comment on a JSP page, the comment reappears on the page as well after sending the request object to the servlet. This is the jsp form:

 <form action="/WebAppOpe/UploadComments" method="post">
                        <textarea name="comment" placeholder="Comment" column="10"></textarea>
                        <input type="submit" value="Post Comment" class="btn-login" name="btn_post" />
                        <input type ="hidden" name="carIdComment" value="${car.carId}" />
 </form>

这是UploadComments URI的servlet代码,用于将请求发送回源.

And this is the servlet code of the UploadComments URI for sending the request back to the source.

        RequestDispatcher rd = request.getRequestDispatcher("model.jsp?" + request.getParameter("carIdComment"));
        rd.forward(request, response);
        response.sendRedirect("model.jsp?"+  request.getParameter("carIdComment"));

推荐答案

由于您只想刷新当前页面,因此ajax是您更好的选择.

Since you just want to refresh the current page,ajax is a better choice for you.

对于您当前的设计,forwardredirect都可以,但是需要注意一些事项:

For you current design,both forward and redirect are okay,but something need to pay attention:

  1. 如果使用redirect,则可以通过url设置参数

  1. if you use redirect,you can set parameters via the url

,您需要查询退出注释,这意味着您可以redirect到新的url并查询数据,或者查询forward之前的数据.

after forward or redirect,you need to query the exits comments,which means that you had can either redirect to a new url and query data, or query the data before forward.

这篇关于使用Servlet类将调用的JSP重定向到其自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆