struts1.2与spring整合手记

<script type="text/javascript"></script>

首先声明几点(注意了):

 

1:struts-config.xml中元素的顺序

如果你的顺序写错了,tomcat会有如下提示:

The content of element type "struts-config" must match "

(display-name?,description?,data-sources?,form-beans?,global-exceptions?,global-forwards?,
action-mappings?,controller?,message-resources*,plug-in*)

". [109]

这就是说,你一定要按照这个顺序来写sturts-config.xml

-------------------------------------------------------------------------

<struts−config>

<data−sources></data−sources>
<form−beans></form− bean>
<global−forwards></global−forwards>
<action−mappings></action−mappings>
<controller />
<message−resource />
<plug−in />

</struts−config>
-------------------------------------------------------------------------

2:web.xml参数顺序

web.xml中参考顺序如下:

---------------------------------

icon?,
display-name?,
description?,
distributable?,
context-param*,
filter*,
filter-mapping*,
listener*,
servlet*,
servlet-mapping*,
session-config?,
mime-mapping*,
welcome-file-list?,
error-page*,
taglib*,
resource-env-ref*,
resource-ref*,
security-constraint*,
login-config?,

-------------------------

3:struts和spring的所须包如下:

--------------------------------

commons-beanutils.jar

commons-digester.jar

commons-logging-1.0.4.jar

log4j-1.2.9.jar

spring.jar

--------------------------------------------------

spring-webmvc-struts.jar(或着spring-web.jar)//如果出现servlet action is not avalilable错误,就是少了这个jar包,因为在sturts-config.xml文件中用到了:<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>和

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn" />

--------------------------------------------------

commons-validator.jar(如果你用到了struts的validator框架,则加入此包)

mysql-connector-java-5.0.4-bin.jar(如果你用到了数据库,则加入此包)

--------------------------------

 

好了,开始配置吧

1:web.xml文件代码如下:

---------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="
http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  
  <servlet>
    <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-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>

---------------------------------------------------------------------------------------------

2:struts-config.xml文件代码如下:

---------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "
http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
    <data-sources />
  <form-beans >
    <form-bean name="loginForm" type="collon.controller.LoginForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="loginForm"
      input="/index.jsp"
      name="loginForm"
      path="/login"
      scope="request"
      type="collon.controller.LoginAction"
      validate="false">
      <forward name="success" path="/success.jsp"></forward>
      <forward name="false" path="/false.jsp"></forward>
    </action>
 
  </action-mappings>
  
  <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
  
  <message-resources parameter="collon.struts.ApplicationResources" />
 
 
<plug-in
       className="org.springframework.web.struts.ContextLoaderPlugIn">
       <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>

</struts-config>

---------------------------------------------------------------------------------------------

3:applicationContext.xml文件代码如下:

---------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
 <bean name="/login" class="collon.controller.LoginAction"></bean>
</beans>

---------------------------------------------------------------------------------------------

4:log4j.properties文件代码如下:

-------------------------------------------

log4j.rootLogger=INFO,stdout,R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log.log
log4j.appender.R.MaxFileSize=1000KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n
log4j.logger.com.foo=INFO

-------------------------------------------

5:commons-logging.properties文件代码如下:

------------------------------------------------------------------------------

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

------------------------------------------------------------------------------

 

声明:

(1)log4j.properties和commons-logging.properties放在 你的工程/src

(2)在login.jsp页面中,form的action一定要有"/",如下<form action="/ssh/login.do" />

(3)struts-config.xml中的<action path="/login"/>与applicationContext.xml中的<bean name="/login"/>是一一对应的,且必须是name="/login"

 

Fighting  之 健康从此开始!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值