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.
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 Component||JSP Component|
|Model||Java Objects put in as request attributes|
|Controller||Your 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:
|rundata||RunData||Reference to request run data object|
|js_peid||String||Portlet unique identifier|
|link||JspLink||Instance of JspLink object|
|portlet||Portlet||Reference to this portlet object|
These can be retrieved from request attributes as in the example below:
String jspeid = (String) request.getAttribute("js_peid");
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.
|ProcessAction||JSP Portlet Action and Action Events|
|Render||Template 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.