Dienstag, 2. Februar 2010

Include the output of a servlet within your jsp

Sometimes its useful to call a servlet and include the output of the servlet within your jsp page. The easiest way to call a servlet from a jsp is the jsp:include tag. Lets assume you have a jsp fragment like this

...

VERSION: <jsp:include page="/InfoServlet?name=VERSION"></jsp:include>

..


this will cause a call to the InfoServlet with the parameter name and the value VERSION. The output will be written by the InfoServlet.
HINT:
The calling servlet has to use the same access method to the response as the jsp and should not close the stream. Otherwise the output of your jsp will stop immediately.
So if you don't know just use
response.getOutputStream() to write to the response.

Keine Kommentare:

Kommentar veröffentlichen