Creating Empty portlet projects on WebSphere Application Server Liberty Profile

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

  1. Click File > New > Project.
  2. In the New Project wizard, select Portlet Project and click Next; then in the Confirm Enablement dialog box, click OK.
  3. In the New Portlet Project wizard, in the Project name field, enter a project name.
  4. From the Target runtime list, select a target runtime environment, such as WebSphere Application Server Liberty Profile.
  5. Click the Modify button for configuration and, for portlet API, select JSR 286 or JSR 168.
  6. Click OK.
  7. In the New Project wizard, click Finish.
  8. A default custom portlet class named <portlet-name>Portlet.java is created and opens by default in the Editor.
  9. Then create a Portlet JSP by using the Web Page wizard for your portlet.
  10. From the Project Explorer view, right-click the name of your portlet project and click New > Other; Then in the New wizard, expand the Web folder, select Web Page, and click Next. The Web Page wizard opens.
  11. 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.
  12. 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()");
    
    }

Feedback