Calling a Portal Page From a Servlet

Frank 30.04.2014

There are many situations in which a servlet has to generate a URL for a portal page. Examples are the generation of a URL on request of a servlet and sending this URL by e-mail, the connection of external systems and jumps to certain portal pages, etc.

Requirements:

* The servlet must be deployed on the portal server (or the underlying Application Server).
* The page to be displayed must have a unique name (see Section 4.1).

Implementation without parameters:

private String PAGENAME = "de.example.test";
private String PORTLETNAME = "de.example.portlet.detail";
private void perform(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException {
     String url = null;
     try {
          MyServerContext serverContext = new
          MyServerContextrequest.getServerName(), "" + request.getServerPort());
          GenericOffLineURLHelper servletHelper =
               UrlHelperFactory.getOffLineURLHelper(FactoryConstants.PortalVersion70);
          url = servletHelper.generateUrl(PAGENAME, PORTLETNAME, null,
          serverContext, true);
     } catch (Exception e) {
     System.out.println("!!!!!! ERROR: " + e.getMessage());
     }
     System.out.println("URL: " + url);
}

Generating the URL using the method “GenerateURL” requires a boolean value that controls whether or not the displayed page will be NonPublic. If it is a NonPublic page then “true” will be specified, so that if no login data is available, the user will be forwarded to the login page first and only then be forwarded to the actual page.

Implementation with parameters:

private String PAGENAME = "de.example.test";
private void perform(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
     String url = null;
     try {
           MyServerContext serverContext = new
           MyServerContextrequest.getServerName(), "" + request.getServerPort());
           GenericOffLineURLHelper servletHelper =
                UrlHelperFactory.getOffLineURLHelper(FactoryConstants.PortalVersion70);
           HashMap map = new HashMap();
           String[] value1 = {"test1"};
           map.put("testPara1", value1);
           url = servletHelper.generateUrl(PAGENAME, PORTLETNAME, map,
               serverContext, true);
    } catch (Exception e) {
          System.out.println("!!!!!! ERROR: " + e.getMessage());
    }
System.out.println("URL: " + url);
}

The portlet can read the parameters with the following snippet:

String value = null;
value = request.getParameter(“NAMEDESPARAMETERS”);

Lernen Sie mehr über:

WebSphere Application Server

WebSphere Portal Server

IBM DataPower

IBM BPM | Process Server

IBM LDAP

Interessantes

Calling a Portlet From a Portlet

Frank 30.04.2014

A portlet calls another portlet that is placed on a different page. The calling portlet generates a URL in the associated processAction method and sets a parameter to be transmitted. The generated URL will appear as a link on the JSP page of the calling portlet. If the link is clicked, the other portlet is […]

Über Uns

Unsere Arbeit

Unsere Partner

Unser Blog

IBM Produkte

Software Engineering

IT Architecture

Workshops

Unternehmen

Produkte

Services

Lösungen