Thursday 2 February 2017

How to develop a very basic JSR 286 Portlet Web Application

how to develop a very basic JSR 286 Portlet Web Application

Steps behind developing a very basic JSR 286 Portlet Web Application that can be deployed to and tested with WebSphere Portal Servers 8.0 and above.

Technologies used:

  • Java EE 6
  • Portlets 2.0 (JSR 286 Portlets)
  • WebSphere Portlet Server 8.0 and above
  • MyEclipse 2015 CI

Step 1: Create a Web Project in MyEclipse

  • To do that, choose File > New > Web Project > Next > provide a name, choose Java EE 6 specification and finish the wizard. 

Step 2: Configure WebSphere Portal Server

  • Right click inside Servers view > New > Server > WebSphere Portal Server 8.0 or 8.5 > Next >
  • Provide Portal Server and AppServer installation directories > Next
  • Provide the username and password for the server
  • Finish the wizard and ensure the new Server is visible in the Servers view
  • If you require additional information on WebSphere Portal Server setup in MyEclipse, please click here.

Step 3: Install JSR 286 Portlet Support

  • Select the project and choose MyEclipse > Project Facets / Capabilities > Install JSR Portlets Facet > Next
  • Choose JSR 2.0 version and select WebSphere Portal Server as the target runtime so the portlet implementation is handled by WebSphere. Then finish the wizard.

how to develop a very basic JSR 286 Portlet Web Application

What this does:
> Installs Portlet Facet to the project.
> Adds the WebSphere Portal Server container to the project.
> Generates a portlet.xml inside WEB-INF folder.

The project is now ready for Portlet development.

Step 4: Create a new Portlet

  • Create a new Java package
  • Right click on the package > choose New > Other > Portlet > Next
  • Provide a name for the portlet, say "MyFirstPortlet"
  • Accept all other defaults and finish the wizard
What this does (screenshots below):
> Creates a new Portlet in the selected package with the doView method pointing to the newly created JSP.
> Creates a new JSP file inside WEB-INF/jsp with default content.
> Updates portlet.xml with the newly created portlet.

how to develop a very basic JSR 286 Portlet Web Application

how to develop a very basic JSR 286 Portlet Web Application

how to develop a very basic JSR 286 Portlet Web Application

Step 5: Modify View


  • Open the JSP file and replace the default content with a form that takes inputs from users, like below. Save and close the file.

how to develop a very basic JSR 286 Portlet Web Application















What this does:
renderResponse.createRenderURL() renders the portlet.
> The form takes user input and upon pressing Submit, dispatches the information to the Portlet for processing.

Step 6: Modify the Portlet


  • Let's modify the portlet to handle the form input from the JSP. Open the class and modify the doView method like below:

how to develop a very basic JSR 286 Portlet Web Application













What this does:
> request.getParameter(..) fetches all the parameter values provided by the user in the JSP.
> The input is then processed to show a simple message back to the user.
> A Try Again link is then added to take the user back to the form to provide a different input and test the portlet again.

Step 7: Deploy and run the portlet

  • Start the portal server by selecting the server in Servers view and then choosing Run.
  • Once the server is started, right click on it and choose Add/Remove Deployments... > select our Portlet project > Add > Finish the wizard.

Step 8: Adding the Portlet to the Portal server

  • To test our portlet, we first need to add our portlet to the WebSphere Portal Server. To do that, open a Web browser and enter http://localhost:<your port>/wps/myportal. Login with the username and password.
  • Turn on Edit Mode from the top right section of the portal page.


  • Press 'Create > Page' to create a new page to which our portlet will be added.
  • Press 'Create > Application'. Then in the search text field, enter "MyFirstPortlet" and hit search. When the results are shown, press the '+' next to our portlet to add it to the page created earlier. 
  • Our portlet should now be available for testing.

2 comments: