You can create and maintain resources for portlet applications
by using the Java™ Specification
Request (JSR 168 and JSR 286) portlet API in portlet projects, which
can be added to a new or existing enterprise application project.
Before you begin
IBM® WebSphere® Application Server Liberty Profile
and required add-ons are installed.
About this task
Use the New Portlet Project wizard
to create empty portlet projects.
Procedure
- Click .
- In the New Project wizard, select Portlet
Project and click Next; then in
the Confirm Enablement dialog box, click OK.
- In the New Portlet Project wizard,
in the Project name field, enter a project
name.
- From the Target runtime list, select
a target runtime environment, such as WebSphere Application Server Liberty Profile.
- Click the Modify button for configuration
and, for portlet API, select JSR 286 or JSR
168.
- Click OK.
- In the New Project wizard, click Finish.
- A default custom portlet class named <portlet-name>Portlet.java is
created and opens by default in the Editor.
- Then create a Portlet JSP by using the Web Page wizard
for your portlet.
- From the Project Explorer view, right-click
the name of your portlet project and click ; Then in the New wizard,
expand the Web folder, select Web
Page, and click Next. The Web
Page wizard opens.
- In the Web Page wizard, specify a
name for your JSP file, accept the default folder for your portlet
project, choose Portlet JSP as the template,
and then click Finish.
- Open the <portlet-name>Portlet.java class
and specify the Portlet JSP name by modifying the doView() method
as follows:
public void doView(RenderRequest request, RenderResponse response) throws
PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
//
// TODO: auto-generated method stub for demonstration purposes
//
// Invoke the JSP to render, replace with the actual jsp name
PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/_TestProject/jsp/html/TestProjectPortletView.jsp");
rd.include(request,response);
// or write to the response directly
//response.getWriter().println("TestProject#doView()");
}