Multiple Pages Inside One Portlet

不羁岁月 提交于 2019-12-03 17:16:28

Sure, a portlet can contain more than one JSP.

You can display any JSP you want via the PortletRequestDispatcher in your doView (or doHelp or doEdit) method:

protected void doView(RenderRequest req, RenderResponse resp)
       throws PortletException, IOException, UnavailableException {
   resp.setContentType("text/html"); 
   String myview = req.getParameter("myview");
   String view = "/WEB-INF/jsp/" + (myview==null ? "bar" : myview) + ".jsp";
   PortletRequestDispatcher dispatcher = 
                                 getPortletContext().getRequestDispatcher(view);
   dispatcher.include(req, resp);
}

You could use a parameter to set the view. In the JSP with the links, you'd need to use the Portlet API to create/encode the links to the Portlet. For example:

<portlet:renderURL>
  <portlet:param name="myview" value="foo"/>
</portlet:renderURL>

(I haven't really kept abreast of JSR286/Portlet 2.0 - this stuff should work with JSR168/Portlet 1.0 - so it is worth checking the new API if you're using it.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!