1.strurs的工作流程
- servlet容器【我们用的是tomcat】启动时,ActionServlet启动,并加载struts配置文件
- 客户端发出*.do请求时,ActionServlet根据配置文件调用相应的Action,并初始化相应的ActionForm,并将其引用传递给Action的execute方法。
- ActionServlet根据struts-config.xml配置文件里的forward配置,将返回结果,forward到客户端。
2.在web.xml中添加
struts的配置主要在两个文件中配置,web.xml适用于所有java web的部署文件,还有struts专用的配置文件struts-config.xml
<!--声明action类 ActionServlet负责接收客户端请求,再由RequestProcessor去分发处理 -->
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param> <!--给出初始化参数及其值-->
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup><!-- 应用程序启动时,即在接受任何客户端请求前,创建的servlet实例数,可以提高应用程序被第一次调用时的相应速度,但是过多的话会消耗服务器资源 -->
</servlet>
<!--debugjsp的servlet-->
<servlet>
<servlet-name>debugjsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>classdebuginfo</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>debugjsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
3.struts-config.xml配置文件
<?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">
<struts-config>
<data-sources /><!--数据源,这里暂不配置,由spring或hibernate来配置-->
<form-beans>
<form-bean name="uploadfileform"
type="org.cims201.struts.formbean.uploadfile.UploadFileForm">
</form-bean>
<!--若干个formbean-->
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="homepage" path="/home"></forward>
<forward name="message" path="/kupload/message.jsp"></forward>
<forward name="error" path="/kupload/error.jsp"></forward>
</global-forwards>
<action-mappings>
<!-- 用户注册的action -->
<action path="/registAction" name="registform">
<!--这里用了spring注释的方式,所以不写 type="org.cims201.action.RegistAction"-->
<forward name="registsuccess"
path="/regist/registResult.jsp">
</forward>
<forward name="registfailure"
path="/regist/registResult.jsp">
</forward>
</action>
<!--若干个action-->
</action-mappings>
<!-- Spring集成Struts -->
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingTilesRequestProcessor" />
</controller>
<message-resources
parameter="org.cims201.struts.ApplicationResources" /><!--资源文件,扩展名为.properties>
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>
<plug-in className="org.cims201.service.job.SchedulerJobs"></plug-in>
<!--插件-->
</struts-config>
//标签库-在web.xml中配置-------------------------------------------------------------------------------------------------------------------
<jsp-config>
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>
/WEB-INF/tags/struts-bean.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>
/WEB-INF/tags/struts-html.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>
/WEB-INF/tags/struts-logic.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>
/WEB-INF/tags/struts-tiles.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/extremecomponents</taglib-uri>
<taglib-location>
/WEB-INF/tags/extremecomponents.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/c</taglib-uri>
<taglib-location>/WEB-INF/tags/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/fn</taglib-uri>
<taglib-location>/WEB-INF/tags/fn.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/fmt</taglib-uri>
<taglib-location>/WEB-INF/tags/fmt.tld</taglib-location>
</taglib>
<!-- jenkov-prizetags-bin-2.6.3 -->
<taglib>
<taglib-uri>/tags/tree</taglib-uri>
<taglib-location>/WEB-INF/tags/treetag.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/request</taglib-uri>
<taglib-location>
/WEB-INF/tags/requesttags.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://www.tonbeller.com/wcf</taglib-uri>
<taglib-location>/WEB-INF/wcf/wcf-tags.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://www.tonbeller.com/jpivot</taglib-uri>
<taglib-location>
/WEB-INF/jpivot/jpivot-tags.tld
</taglib-location>
</taglib>
</jsp-config>
data-source 在spring的beans.xml中的配置
<bean id="dataSource"
class="org.logicalcobwebs.proxool.ProxoolDataSource"
destroy-method="close">
<property name="driver">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="driverUrl">
<value>
jdbc:oracle:thin:caltksp/caltksp@127.0.0.1:1521:ORCL
</value>
<!--用户名和密码写在一起才调用成功,不然会报 调用无效的参数 错误,下面设置用户名和密码的property好像是无效的,其它数据库也是这样
比如mysql的也要把用户名和密码写在url里:<property name="driverUrl" value="jdbc:mysql://localhost:3306/blogdb?user=lizongbo&password=lizongbo" />
-->
</property>
<property name="user"><!-- 必须在这里也设置,但是 proxool却不使用它,或许是个bug-->
<value>caltksp</value>
</property>
<property name="password"><!-- 必须在这里也设置,但是 proxool却不使用它,或许是个bug-->
<value>caltksp</value>
</property>
<property name="alias">
<value>caltksp</value>
</property>
<property name="houseKeepingSleepTime">
<value>90000</value>
</property>
<property name="prototypeCount">
<value>5</value>
</property>
<property name="maximumConnectionCount">
<value>1000</value>
</property>
<property name="minimumConnectionCount">
<value>10</value>
</property>
<property name="trace">
<value>false</value>
</property>
<property name="verbose">
<value>false</value>
</property>
</bean>