以表格形式请求调度程序
我在 jsp 文件中有一个表单,我用它来获取用户详细信息。单击提交按钮后,表单操作已设置为另一个 jsp 文件,其中详细信息将插入到数据库中。 但在此之前,一旦用户输入用户 ID,就会出现一个检查可用性按钮。 单击按钮后,我希望控件转到另一个 jsp 页面,并将用户名作为参数。我在那里检查可用性。我想返回对前一个jsp文件的响应。 这可以使用“请求调度程序”来完成吗?如果是,请有人解释一下请求调度程序的包含和转发方法。我尝试在网上搜索它。只有代码可用。我想知道这个请求调度程序是什么以及它是如何工作的。
I have a form in a jsp file, which I have used to get the user details. On clicking the submit button, the form action has been set to another jsp file where the details are inserted into the database.
But before that as soon as the user enters the userid, there is a check availability button.
On clicking the the button I want the control to go to another jsp page along with the username as a parameter. There I am doing the check availability. I want to return the response to the previous jsp file.
Can this be accomplished using the 'request dispatcher'. If yes can someone pls explain the include and forward methods of the request dispatcher. I have tried searching for it on the net. There is only code available. I want to know what this request dispatcher is and how it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请求调度程序将请求调度到给定的目标。请求调度程序基本上将控制权传递给给定的目标。对于 JSP,JSP 将处理给定的请求并将其输出发送到给定的响应。
include()
方法允许您在控件返回后继续使用响应,以便您可以在必要时添加一些数据。不允许包含的目标操作响应标头。include()
的目标应该是最终响应的一部分。forward()
方法允许您将控制权完全传递给给定的目标。允许转发的目标操纵响应标头。forward()
的目标应该是您想要充分展示的整个 JSP 文件本身(但反过来也可以包含其他 JSP)。在这种情况下,您需要发送转发。哦,这种工作不属于 JSP,而是属于 Servlet。否则,当您尝试转发请求的 JSP 已经向响应发送了一些数据时,您可能会遇到
IllegalStateException
。The request dispatcher dispatches the request to the given target. The request dispatcher basically passes the control to the given target. In case of JSPs, the JSP will then work with the given request and send its output to the given response.
The
include()
method allows you to continue using the response after the control comes back, so that you can if necessary add some data. The included target is not allowed to manipulate the response headers. The target of aninclude()
should be a partial of the final response. Theforward()
method allows you to pass the control fully to the given target. The forwarded target is allowed to manipulate the response headers. The target of aforward()
should be the entire JSP file itself which you want to present in its full glory (which in turn can however include other JSPs).In this case, you need to send a forward. Oh, this kind of job doesn't belong in a JSP, but in a Servlet. You may otherwise face
IllegalStateException
s when the JSP wherein you're trying to forward the request has already sent some data to the response.