How to forward the servlet output to the jsp page?
This means that the results will be displayed in JSP page.
You normally do not use the servlet to generate the HTML output. You normally use JSP / EL for this by using out.write
and the ritual is considered bad behavior for broadcasting HTML content, for example:
Secure zero code (HTPervlet request request, HTTPPreserve response response) {Object data = "Some data, a string or maybe a JavanBan"; Request.setAttribute ("data", data); Request.getRequestDispatcher ("/ WEB-INF / page.jsp") Forwarded (request, response); }
In this web.xml, click & lt; Url-pattern & gt; Map
for / page
for example. To prevent direct access, place JSP in / WEB-INF
. Then in JSP you can use EL () to access the Scotch attributes:
& lt; P & gt; Data for servlet: $ {data} & lt; / P & gt; Call
servlet by http://example.com/context/page
. simple as that. In this way you control output and presentation in one place, JSP.
No comments:
Post a Comment