Creating Struts portlet JSP files
As is typical when creating other Struts resources, there are two methods to launch the
Web Page wizard for creating JSP files in a Struts project:
- If you use the Web diagram editor, a page is automatically created for you when you name the
Web Page Node that you dropped on editor's free-form surface from the
Web Parts palette drawer. If you plan to use this method, you will need to have the Web diagram (*.gph) file available in the project.
- You can also use the standard menu options to access this wizard to create a JSP file outside the context of the Web diagram editor.
The recommended method for creating new Struts portlet JSP files is to design the Struts portlet application using the Web diagram editor. When page nodes are dropped and named, the page artifact associated with the node will be created. As you update your diagram with connections of pages to actions, the underlaying artifacts will be updated for you as well.
JSP files created for Struts portlet projects using the Web Page wizard are compliant in a Portal environment, and have the following characteristics:
- They do not contain document-level markups, such as <head> and <body> tags. In addition, DOCTYPE declarations are also not included.
- Struts tags automatically include references to resources such as Web pages, images, or Struts actions on execution. A resource reference using Struts would be coded like this sample: <html:image src="icons/image.gif"/>.
Note: If you are using HTML tags for resource references, the reference must be encoded or decoded with the portlet API. For example: <image src='<%= response.encodeURL("/icons/image.gif") %>'/>
- Select
File | New | Other. In the New wizard page, expand the
Web folder and choose
Web Page, then click Next. The New Web Page wizard will open.
- Specify a file name and the appropriate folder for the file. Depending upon the your context in the project, or the method that you used to create the file, this field may be pre-filled.
- Select Portlet JSP as the template.
- Click the
Options button to configure items such as document markup and style sheets; otherwise, click Finish. If you chose Options, use the left pane of the window to supply any of the encoding, content type, and document type information that you would typically provide for a JSP file.
- Document Markup - Supply any of the encoding content type, and document type information that you would typically provide for a JSP file.
- J2EE - Create init() and destroy() method stubs for the JSP file by selecting the appropriate check boxes, as applicable. Registering the JSP file as a servlet in the Web deployment descriptor is not applicable to portlets, so options related to the
Add to web.xml check box should be disabled. If they are enabled, clear the check box to disable them.
- Style Sheets - The style sheet option is disabled for portlets.
- Tag Libraries - Click the
Add button to locate a TLD file or a JAR file that contains a TLD file to can add tag libraries from a variety of sources. If the web page is being created for Struts portlet (IBM® or JSR168) facet version 6.0 or higher, taglib entries are now : http://struts.apache.org/tags-html and http://struts.apache.org/tags-bean.
Note: There is a Portlet JSP option, that specifies the Struts Portlet JSP, then the appropriate taglib entries will be added to the page, without you having to add them in the Tag Libraries page.
For JSR 168 API portlets, the
http://java.sun.com/portlet URI can also be included for portlet initialization. The location of these TLD files in your project is based on the your project configuration.
- After you have configured options for your JSP file, click
Close.
- Click Finish. The JSP file, with appropriate markup, is created and automatically opened in the editing pane.
Related concepts
Creating Struts portlets and projects
Related reference
Differences between Struts 1.1 and SPF tag library classes