论坛首页 入门技术论坛

struts1.2+spirng多配置问题

浏览 2737 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-09-27  
struts+spring多配置问题

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>
    <!-- loginmodel-->
    <init-param>
      <param-name>config/loginview</param-name>
      <param-value>/WEB-INF/struts-loginview-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>
  <filter>
    <filter-name>SetCharactorEncoding</filter-name>
    <filter-class>org.tie.util.SetCharactorEncoding</filter-class>
    <init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
  </filter>
  <filter-mapping>
    <filter-name>SetCharactorEncoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
 
</web-app>

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-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
   <action path="/toModule" type="org.apache.struts.actions.SwitchAction"/>
  </action-mappings>

  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
 
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
  </plug-in>
 
</struts-config>

struts-loginview-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="com.lib.loginmodel.form.LoginForm" />
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="loginForm"
      input="/loginview/login.jsp"
      name="loginForm"
      path="/login"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy">
      <forward name="success" path="/homepage/mainwindow.jsp" />
      <forward name="failure" path="/loginview/login.jsp" />
    </action>
  </action-mappings>

  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
 
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
  </plug-in>
 
</struts-config>

spring配置
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 id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/officeinfo</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/lib/database/Logininfo.hbm.xml</value>
<value>com/lib/database/Codemanager.hbm.xml</value>
<value>com/lib/database/Deptinfo.hbm.xml</value>
<value>com/lib/database/Peopleinfo.hbm.xml</value>
<value>com/lib/database/Codecomparison.hbm.xml</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate"
     class="org.springframework.orm.hibernate3.HibernateTemplate">
    <constructor-arg ref="sessionFactory"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory">
       <ref local="sessionFactory"/>
      </property>
    </bean>
   
    <bean id="loginDao" class="org.lib.loginmodel.HibernateLoginDao">
   <property name="template" ref="hibernateTemplate"/>
</bean>

<bean id="loginInfoFacade" class="org.lib.loginmodel.BusinessFacadeForLoginInfo">
<property name="loginDao" ref="loginDao"/>
</bean>

<bean id="businessfacadeforlogininfoProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"></ref>
</property>
<property name="target">
<ref bean="loginInfoFacade" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean name="/login" class="com.lib.loginmodel.action.LoginAction"
abstract="false" singleton="false" lazy-init="default"
autowire="default" dependency-check="default">
<property name="loginInfoFacade">
<ref local="loginInfoFacade"/>
</property>
</bean>
</beans>

页面
login.jsp


<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
   
    <title>login.jsp</title>
   
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
  </head>
  <link href="<%= request.getContextPath() %>/css/initial.css" rel="stylesheet">
<script src="<%=request.getContextPath()%>/js/initializewindow.js"></script>
    <script language="javascript">
function gosubmit(){
if (window.name != "loginpage"){
popwin("loginpage",8888,796,'about:blank');
window.opener=null;
        window.close();
}
   return true;
}
</script>
<body background="<%=request.getContextPath()%>/pic/homepagepic/blackpic.jpg">
      <html:form action="/login" target="loginpage" onsubmit="gosubmit()" focus="username">
  <table width="100%">
   <tr>
     <td height="200" colspan="2"></td>
   </tr>
  </table>
  <table width="100%">
   <tr>
     <td width="60%" height="200" colspan="2"></td>
<td width="40%" height="200" colspan="2">
   <table width="100%">
     <tr>
   <td>用户名: <html:text property="username" size="25"/><html:errors property="username"/></td>
</tr>
<tr>
   <td>密&nbsp;&nbsp;&nbsp;&nbsp;码: <html:password property="password" redisplay="false" size="27"/><html:errors property="password"/></td>
</tr>
<tr>
  <td align="center">
   <html:submit value="登&nbsp;&nbsp;录" styleClass="loginbuttonstyle"></html:submit>
   <html:reset value="撤&nbsp;&nbsp;消" styleClass="loginbuttonstyle"></html:reset>
  </td>
</tr>
   </table>
</td>
   </tr>
  </table>
</html:form>
  </body>
</html:html>

错误提示javax.servlet.ServletException: Cannot retrieve mapping for action /login


   发表时间:2007-09-27  
请大家看一下
0 请登录后投票
   发表时间:2007-09-27  
问题解决了
<init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml,/WEB-INF/struts-config-loginview.xml</param-value>
    </init-param>
就可以
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics