Introduction to JSPt

JSP (Java Server Pages) is a technology based on the Java language and enables the development of dynamic web sites. JSP was developed by Sun Microsystems to allow server side development. JSP files are HTML files with special Tags containing Java source code that provide the dynamic content. JSP is easy to learn and allows developers to quickly produce web sites and applications in an open and standard way. JSP offers a robust platform for web development.

  • 1. Multi platform
  • 2. Component reuse by using JavaBeans and EJB.
  • 3. Separation of content from code
  • 4. You can take one JSP file and move it to another platform, web server or JSP Servlet engine.

Jetspeed has a JSP templating service built directly into the Jetspeed engine. Similar to Velocity, you can base your portlets on JSP. This means that your portlets will also follow the MVC design pattern, separating content from code.

The examples in Tutorial 5 and Tutorial 6 were useful for you to learn the Portlet interface. However, overriding the getContent method of the portlet interface is not good practice. We recommend abstracting the content generation phase by basing your portlets on one of the MVC-based portlets provided in the Jetspeed distribution; such as VelocityPortlet, JSPPortlet, XSLTPortlet, RSSPortlet or HTMLPortlet.

A JSP portlet is made up of the typical MVC components:

MVC ComponentJSP Component
ModelJava Objects put in as request attributes
ControllerYour JSP Action

The controller is your JSP Action class. The base JspPortlet class should rarely have to be modified. Your view is a JSP template, which will generate the content of your portlet by pulling out dynamic model information from the request attributes. In addition to the standard JSP variables (request, response, session, etc), the following variables are available in the model:

rundataRunDataReference to request run data object
js_peidStringPortlet unique identifier
linkJspLinkInstance of JspLink object
portletPortletReference to this portlet object

These can be retrieved from request attributes as in the example below:

String jspeid = (String) request.getAttribute("js_peid");

Also, your JSP template can make use of any of the available tags from the Jetspeed tag library. See JSP1_1andJetspeedTagLibrary portlet for comprehensive list of examples.

The getContent method of the JspPortlet should never be edited. All content is generated by the template, as designed in our MVC design pattern.

The Life Cycle phases of a portlet are also enhanced with the JSP portlet.

ProcessActionJSP Portlet Action and Action Events
RenderTemplate is called by JSP Portlet

JSP portlets are really about dynamic content. If you have static content, there is no real benefit to using a JSP portlet; take a look at one of the static content generation portlets such as the HTMLPortlet instead. The basic function of JSP is really very simple, it substitutes live Java objects into a JSP template. There is an online tutorial with great examples here.