如何从servlet执行JSP,并将响应返回给servlet? [英] How to execute JSP from servlet, and get the response back to the servlet?

查看:246
本文介绍了如何从servlet执行JSP,并将响应返回给servlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试执行以下操作:

我有一个Servlet,它执行一些代码.
在一种情况下,我需要创建一个包含内部内容的表单元素,并将其写回到"out"变量中.

问题是,我不想使用字符串生成器来执行此操作,我想创建一个保存表单的JSP页面,并将请求参数转发给它,
而且,当它完成创建页面时,我想取回整个HTML,然后将其打印到"out"(在servlet中)

Hello, i''m trying to do the following:

i have a servlet, which executes some code.
in a case, i need to create a form element with stuff inside, and write it back to the "out" variable.

the problem is, i dont want to use a string builder to do it, i''d like to create a JSP page which holds the form, and forward the request params to it,
but also, when it finishes creating the page, i''d like to get the whole HTML back, and then print it to the "out" (in the servlet)

is it possible?

推荐答案

使用RequestDispatcherforward 方法.请参阅此处进行讨论: http://www.theserverside.com/discussions/thread.tss?thread_id= 2472 [^ ].

但是,请让JSP 负责输出.这就是JSP编程中的过程:让servlet处理所有业务逻辑和数据访问内容,并使用JSP 将整个内容呈现为HTML.

问候,

—MRB
Use the RequestDispatcher''s forward method. See here for a discussion: http://www.theserverside.com/discussions/thread.tss?thread_id=2472[^].

Please let the JSP take care of the output though. That''s the procedure in JSP programming: Let the servlets handle all the business logic and data access stuff and the JSP is used to render the whole thing to HTML.

Regards,

—MRB


这篇关于如何从servlet执行JSP,并将响应返回给servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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