XIV. 部署 Stringbeans爲ROOT上下文
------------------------------------------
1. 在 $TOMCAT_HOME下建立stringbeans目錄.
2. 解壓 stringbeans.war 到剛建立的stringbeans目錄.
3. 修改$TOMCAT_HOME/conf目錄下的配置文件server.xml
在Host標籤下,添加以下的context
Context path= docBase=..stringbeans debug=0
Typically there is Tomcat's ROOT context. If it is enabled, rename
it to any name. e.g.
Context path=root docBase=ROOT debug=0
4. 啓動 Tomcat.
Windows $TOMCAT_HOMEbinstartup.bat
Unix or Linux $TOMCAT_HOMEbinstartup.sh
5. You can connect to Stringbeans Portal by typing only your server name
(plus port number if you are using other than port 80).
e.g. httplocalhost8080
XV. 使用 Stringbeans Struts 橋
------------------------------------
Stringbeans 的發佈版本里包含有Struts 橋 ,本身支持 Struts應用部署爲符合JSR-168
規範的應用。
下列步驟完成在Stringbeans上下文中部署Stru應用。ts
如果在不同的上下文環境中佈置Struts應用,請按下面的綁定Struts橋的發行版(在單獨的包中)的安裝說明的步驟
1. 在$STRINGBEANS_HOME/WEB-INF/目錄下的portlet.xml中增加Struts portlet的配置
portlet 的定義必須滿足:
- 指定 com.nabhinc.portlet.strutsbridge.StrutsPortlet 作爲 portlet-class
- 指定 ServletContextProvider 初始化參數爲
com.nabhinc.portlet.strutsbridge.impl.ServletContextProviderImpl.
例如:
<portlet>
<description>....</description>
<portlet-name>....</portlet-name>
<display-name>....</display-name>
<portlet-class>com.nabhinc.portlet.strutsbridge.StrutsPortlet</portlet-class>
<init-param>
<name>ServletContextProvider</name>
<value>com.nabhinc.portlet.strutsbridge.impl.ServletContextProviderImpl</value>
</init-param>
<init-param>
<name>ViewPage</name>
<value>....</value>
</init-param>
<init-param>
<name>HelpPage</name>
<value>....</value>
</init-param>
<expiration-cache>-1</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>....</title>
<keywords>....</keywords>
</portlet-info>
</portlet>
ViewPage, HelpPage 和 EditPage 分別定義 view, help 和 edit 模式.
參照“已知的問題”章節,可見使用Struts橋改變模式時可能遇到的問題。
3.. 修改$STRINGBEANS_HOME/WEB-INF 目錄下的web描述文件,裏面包含Struts應用的配置。修改servlet class 必須爲action Servlet 。
- 在action Servlet.中,用org.apache.portals.bridges.struts.PortletServlet 代替
org.apache.struts.action.ActionServlet
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.portals.bridges.struts.PortletServlet</servlet-class>
<init-param>
:
:
</servlet>
4. 配置 Struts 應用程序
在進行後面的步驟前,Struts 應用程序佈置必須符合“假定項目”要求的規範
- Struts 橋包含的jar文件裏含有四個增強的標籤庫(提供了對
Struts HTML JSP (包含 EL 變量)的支持. 分別是:
struts-portlet.tld
struts-portlet-e;.tld
struts-1.2.4-portlet-html.tld
struts-1.2.4-portlet-html-el.tld
這些增強的Struts HTML JSP 標籤(htmlform, htmllink, htmlrewrite,
htmlrewrite, and htmlimg) 用來解析資源url ,如圖片 javascripts 以及樣式表等等
想使用這些標籤,需要先在web.xml文件中定義這些標籤的映射。如下:
<%@ taglib uri=”http://portals.apache.org/bridges/struts/tags-portlet-html” prefix=”html” %>
或者
<%@taglib uri=”http://portals.apache.org/bridges/struts/tags-portlet-html-el “prefix=”html-el” %>
對於 html鏈接,html重寫,附加的actionURL屬性,renderURL屬性或resourceURL屬性,可以指定URL 生成或重寫的類型。如果沒有指定,默認是renderURL=true
在引用圖片時,使用html標籤,會有一個小的改變。例如:
<img src=..images/struts-bridge.gif>
改成
<html:image src=”..images/struts-bridge.gif” />
- 在增加的上面的 html link 屬性, url 類型必須在
struts-portlet-config.xml ( 如果不存在,您需要在$STRUTS_APP_HOMEWEB-INF 目錄創建這個文件)中指定.
Action 或 解析的URL 的所在路徑都要配置。資源路徑應該是資源URL類型。
通常的struts-portlet-config.xml 的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<render-context>
<attribute name="errors"/>
<attribute name="message" keep="true"/>
</render-context>
<portlet-url-type>
<action path="/shop/add"/>
<action path="/shop/switch"/>
<action path="/shop/newOrder"/>
<render path="/shop/newOrderForm"/>
<action path="/shop/listOrders"/>
<resource path="/images/"/>
</portlet-url-type>
</config>
如果需要各個請求這間保留特定的請求參數,render-context 需要用到。render-context
這個保留屬性使消息對象在下次Action請求或URL改變時都能可用。沒有這個屬性,這些對象僅僅只能使用一次。
關於 Struts 使用的完整說明在:
http://portals.apache.org/jetspeed-2/multiproject/portals-bridges-struts/features.html