Struts配置
經(jīng)過幾天的努力和朋友的幫助,Struts終于搞清楚了
環(huán)境 resin3.0.12+struts1.1
1、 Jsp(視圖)
2、 actionForm
3、 action
4、 模型
視圖內(nèi)容:
有標(biāo)簽和html語(yǔ)言組成。
例如:
<%@ include file="taglibs.jsp" %>
<%-- 登錄驗(yàn)證視圖 2005/04/27 lanlanq --%>
<html:errors/>
<html:form action="/Logon.do">
<center>
<table border="0" width="100%">
<tr>
<th align="right">
<bean:message key="prompt.username"/>
</th>
<td align="left">
<html:text property="userName" size="15" maxlength="15" />
</td>
</tr>
<tr>
<th align="right">
<bean:message key="prompt.password"/>
</th>
<td align="left">
<html:password property="password" size="15" maxlength="15" />
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" >
<bean:message key="button.logon"/>
</html:submit>
</td>
<td align="left">
<html:reset>
<bean:message key="button.reset"/>
</html:reset>
</td>
</tr>
</table>
</center>
</html:form>
首先配置一下resin3.0.12
然后再工程目錄下的WEB-INF下創(chuàng)建lib文件夾,增加struts的支持類包
然后創(chuàng)建TLD文件
struts-bean.tld
struts-html.tld
struts-logic.tld
這三個(gè)標(biāo)記庫(kù)文件
以便在Jsp中進(jìn)行調(diào)用。
然后創(chuàng)建struts-config.xml
內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!--
This is the Struts configuration file for the "Hello!" sample application
-->
<struts-config>
<!-- ======== Form Bean Definitions =================================== -->
<form-beans>
<form-bean name="HelloForm" type="hello.HelloForm"/>
<form-bean name="logonForm" type="member.forms.LogonForm"/>
</form-beans>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<!-- Say Hello! -->
<action path = "/HelloWorld"
type = "hello.HelloAction"
name = "HelloForm"
scope = "request"
validate = "true"
input = "/DateSouce/hello.jsp"
>
<forward name="SayHello" path="/DateSouce/hello.jsp" />
</action>
<action path = "/Logon"
type = "member.actions.LogonAction"
name = "logonForm"
scope = "request"
validate = "true"
input = "/DateSouce/error.jsp"
>
<forward name="Success" path="/DateSouce/sucess.jsp" />
</action>
</action-mappings>
<!-- ========== Message Resources Definitions =========================== -->
<message-resources parameter="application_ch_CN"/>
</struts-config>
這個(gè)文件是在運(yùn)行web服務(wù)器是首先要去找的配置文件
其中的
<form-beans>
<form-bean name="HelloForm" type="hello.HelloForm"/>
<form-bean name="logonForm" type="member.forms.LogonForm"/>
</form-beans>
表示jsp文件指定的actionForm文件
其中的
<action-mappings>
<!-- Say Hello! -->
<action path = "/HelloWorld"
type = "hello.HelloAction"
name = "HelloForm"
scope = "request"
validate = "true"
input = "/DateSouce/hello.jsp"
>
<forward name="SayHello" path="/DateSouce/hello.jsp" />
</action>
<action path = "/Logon"
type = "member.actions.LogonAction"
name = "logonForm"
scope = "request"
validate = "true"
input = "/DateSouce/error.jsp"
>
<forward name="Success" path="/DateSouce/sucess.jsp" />
</action>
表示jsp中調(diào)用Html:form中的action=Logon.do文件的映射。
其中的name和actionForm中的name保持一致。
如果validate=”true”表示要執(zhí)行actionForm的validate錯(cuò)誤處理。
<message-resources parameter="application_ch_CN"/>
表示國(guó)際標(biāo)準(zhǔn)化,再jsp頁(yè)面中的文字說(shuō)明都是通過application文件指定。
創(chuàng)建actionForm時(shí)注意,在通過JBuilder生成actionForm時(shí)注意屬性名和jsp中的屬性名字保持一致,然后創(chuàng)建action,得execute方法,進(jìn)行邏輯處理。