JSPs & Portlets: Forwarding to a JSP from doView in JSR168

JSPs & Portlets: Forwarding to a JSP from doView in JSR168



Part 1 of this 2 part tutorial demonstrates how to forward to a JSP, Java Server Page, from a JSR-168 Portlet. The full tutorial can be viewed here:

This link also provides the Java Source code, deployable war for JetSpeed/Pluto/WebSphere/LifeRay/OpenPortal, etc.

In a good model-veiw-controller type of application, a Java centric component should never be polluted with lots of lousy html.

With typical servlet and struts based applications, html is usually generated by a Java Server Page (JSP); in this regard, portlet applications are no different.

However, portlet applications do present some unusual complications when deferring to a JSP for markup generation.

How does a JSP link back to a specific portlet on a page? How does a portlet call a JSP? How do we gain access to the portlet specific PortletRequest and PortletResponse object in JSP?

This tutorial deals with basic JSP development, and the issues that present themselves when deferring to a JSP for markup generation.

Please support our site, link to us, buy some books, and remember: Happy Java!

public class JSPDisplayPortlet extends GenericPortlet {

protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType(request.getResponseContentType());
String url = “/welcome.jsp”;
getPortletContext()
.getRequestDispatcher(url).include(request,response);
}

For Hibernate3 & JPA Tutorials and Sample Code:

For mock SCJA and SCJP certification exams:

Leave a Reply

Your email address will not be published. Required fields are marked *