---
title: "生成IBM Portal格式的URL"
author: "absolute"
date: "2007-08-08T17:16:48Z"
tags: []
slug: "ibm-portal-url"
draft: false
lastmod: "2007-08-08T17:16:48Z"
id: 110209
url: "https://absolute.iteye.com/blog/110209"
---

最近做了个portal项目，用IBM的Portal Struts Framework做的，因为很多标签都用不了，所以就自己写了个。让我感觉自豪的是写了个portal版本的displaytag标签，最主要的就是要生成portal独有的url格式了，还是贴代码吧。

java 代码

01. public static String createURL(PageContext pageContext, String action,
02. Map params) {
03. HttpServletRequest request = (HttpServletRequest) pageContext
04. .getRequest();
05. StringBuffer results = new StringBuffer();
06. PortletApiUtils portletUtils = PortletApiUtils.getUtilsInstance();
07. if (portletUtils != null) {
08. PortletURIAttributes uriAttributes = new PortletURIAttributes();
09. uriAttributes.setUriType("standard");
10. uriAttributes.setWindowState(null);
11. Object portletURI = portletUtils.createPortletURIWithStrutsURL(
12. request, calculateURL(pageContext, action, params),
13. uriAttributes);
14. results.append(portletURI.toString());
15. } else {
16. results.append(calculateURL(pageContext, action, params));
17. }
18. return results.toString();
19. }
20. private static String calculateURL(PageContext pageContext, String action,
21. Map params) {
22. String url = null;
23. try {
24. String page = null;
25. String href = null;
26. String forward = null;
27. url = WpsRequestUtils.computeURL(pageContext, forward, href, page,
28. action, params, null, false, false);
29. } catch (MalformedURLException e) {
30. e.printStackTrace();
31. }
32. return url;
33. }