Forums Register Login

RequestDispatcher - getting access to the returned html

+Pie Number of slices to send: Send
Hi there,

I have a servlet that uses the following code to include the output from a JSP script:



Which works as expected.

But what I need is for my servlet to be able to access the actual html returned by "CallMe.jsp". Is this possible? If so how?

Thanks!
+Pie Number of slices to send: Send
Servlet is a good Controller. using servlet in View layer is Poor practice .

Ichiro wrote:
But what I need is for my servlet to be able to access the actual html returned by "CallMe.jsp". Is this possible? If so how?



when you try yourself, you get more clear understanding
+Pie Number of slices to send: Send
You may have to use ServletResponseWrapper.

http://download-uk.oracle.com/docs/cd/A97329_03/web.902/a95878/filters.htm#998358
Check the last example.
+Pie Number of slices to send: Send
Thanks for the fast responses.

I checked the url provided below but have another question.

http://download-uk.oracle.com/docs/cd/A97329_03/web.902/a95878/filters.htm#998358
Check the last example.



With this example the name of the called JSP file has to be know in advance in order to set up the filter in the web.xml file. Is this correct?

Unfortunately the JSP's to be called by my program are comming from a database so there is no way to set up web.xml in advance.

Therefore this solution may not eb right for me, but the article was informative so thank you.
+Pie Number of slices to send: Send
 

Ichiro Takeshita wrote:
With this example the name of the called JSP file has to be know in advance in order to set up the filter in the web.xml file. Is this correct?



Example shows with a JSP.. But you can achieve the same with the RequestDispatcher.include too.. by applying the same concept of wrapper.
+Pie Number of slices to send: Send
You'll need a response wrapper.

As to *why* you want this... that's a more interesting question. JSP is a poor technology for generalized out-of-container templating; I'd consider using something else, like FreeMarker, Velocity, etc.
+Pie Number of slices to send: Send
It's unclear what you want to do with the import result, but if you're using JSP here are a couple of options provided by JSTL:

1) Use to capture the result in a scoped var of type String without including it in the page's output. You can always include it later if you want.

2) Use to expose a scoped var of type Reader that can be used to process the result without including it in the page's output. In this case, importReader has nested visibility - meaning that it cannot be accessed after the end tag for <c:import>. The <util:importHandler> tag is just an example and you would need to either create your own tag or use an existing one. A "real" example that parses the result into a scoped var of type Document:
Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1384 times.
Similar Threads
<url-pattern> element
Understanding problem in RequestDispatcher
Can't get RequestDispatcher forward() method or response.sendRedirect() to work
Forwarding request to servlet outside the webapp
url is changing by requestdispatcher
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:15:20.