在JSP的当前页面上显示表单处理结果 [英] Display form-processing results on current page in JSP
问题描述
目前,我能够将一些表单数据从HTML页面发送到Servlet,进行处理,然后通过转发/重定向到displayresults.jsp页面来返回结果;但是我想知道是否有一种方法可以以这种方式处理表单提交,然后将结果返回到初始页面?这样我想返回的内容就会显示在表格下方.
Currently I'm able to send some form data from an HTML page to a Servlet, process it, and return the result by forwarding/redirecting to a displayresults.jsp page; However I'm wondering if there's a way to process a form submission in this fashion and then return the results to the initial page? So that whatever I wish to return shows up below the form.
最后的想法是将搜索功能放在顶部,然后将搜索结果显示在同一页面的下方.
The idea in the end will be to have a search function up top, then have the search results appear below on the same page.
推荐答案
是
- 将结果从servlet中粘贴到请求对象中
- 让servlet 转发回到请求页面
- 在JSP中添加一些代码,以从请求对象中提取结果并显示出来
- Stick the results into the request object from within the servlet
- Get the servlet to forward back to the request page
- Add some code into the JSP to pull out the results from the request object and display them
请参见简单示例 http://www .tek-tips.com/viewthread.cfm?qid = 1189624& page = 11
如果您的用例意味着您将从其他地方的搜索结果中跳出来,然后返回,则您可能希望在会话中保留搜索结果.
If your usecase means that you'll be jumping from the search results elsewhere and back you may wish to maintain the search results in the session.
这篇关于在JSP的当前页面上显示表单处理结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!