问题描述
我很好奇是否有人知道单个portlet是否可能包含多个页面,让我们说JSP页面。此外,是否可以链接到同一个portlet中的这些不同页面?
I am curious if anyone knows if it is possible for a single portlet to contain multiple pages, let's say JSP pages. Furthermore is it possible to link to these different pages within the same portlet?
例如。假设我有一个portlet。在这个portlet中,我希望初始视图是一个JSP页面,它只有5个链接到5个不同的JSP页面。当用户单击这5个链接中的一个时,它会将相应的JSP页面加载到portlet中。
For example. Let's say I have a single portlet. And in this portlet I want the initial view to be a JSP page with just 5 links on it to 5 different JSP pages. And when a user clicked on one of these 5 links, it would load the appropriate JSP page into the portlet.
最终目标基本上是一个包含在portlet中的小型迷你网站。
The end goal would basically be a little mini website all contained inside a portlet.
现在,我明白了这可能不是portlet的最佳用途,但是为了我正在开发的项目,我仍然想知道它是否可行。
Now, I understand that this might not be the best use of a portlet, but for the sake of a project I am working on, I still would like to know if it is possible.
谢谢!
推荐答案
当然,一个portlet可以包含多个JSP。
Sure, a portlet can contain more than one JSP.
您可以通过(或 doHelp
或 doEdit
)方法:
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);
}
您可以使用来设置视图。在带有链接的JSP中,您需要使用Portlet API来创建/编码指向Portlet的链接。例如:
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>
(我还没有及时了解JSR286 / Portlet 2.0 - 这些东西应该可行使用JSR168 / Portlet 1.0 - 如果您正在使用它,则值得检查新API。)
这篇关于一个Portlet内的多个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!