问题描述
我试图借助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.
对于您当前的设计,forward
和redirect
都可以,但是需要注意一些事项:
For you current design,both forward
and redirect
are okay,but something need to pay attention:
-
如果使用
redirect
,则可以通过url设置参数
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重定向到其自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!