Run JSP inside a servlet

T

Thomas S.

Hi there!

I want to render dynamically SQL-Statements. These statements are rendered
inside an servlet to execute them on a SQL server and show the result via
JSP. The SQL-Statements should be placed outside the Java source so they are
editable for non-programmers also.

To make the dynamic rendering easy I decided: Why not use the JSP engine to
do just this? Therefor I make a JSP file that only contains SQL code. Via
Struts-Taglibs I take parameters via Request-Scope and put together the SQL
statement I need.

The executed servlet should open the JSP file, let it be handled by the
servlet container, and catch the result as a string. This result is not to
be shown on the clients browser but to be used as a statement for the SQL
server.

Problem is: I need to run this JSP serverside in the same session context
that the client is using for his browsing session. The JSP should be handled
by the same Tomcat process that handles the clients complete session.

Therefor the

HttpServletRequest.getRequestDispatcher( "my_jsp_file.jsp" ).include( HttpServletRequest, HttpServletResponse )

popped into my mind. Problem is: This Dispatcher needs another HttpServletResponse
object, because the result of this should not be sent to the clients browser. I want
to get the response stream as String to use it as SQL statement.

Cloning is not possible and a wrapper doesn't work, because the interfaced
methods (when overwritten) cannot prevent the submit of the rendered stream
to the client browser inside the include()-method.

Has anyone an idea how to get a HttpServletResponse object that isn't connected
to the clients browser but just can provide a rendered code as String for further
serverside handling?

Looking forward to your suggestions!
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top