• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher - getting access to the returned html

 
Ichiro Takeshita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ichiro Takeshita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kris Schneider
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!