strut.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <package name="web" extends="struts-default" namespace="">
<default-interceptor-ref name="paramsPrepareParamsStack" />
<!--登录管理 -->
<action name="login"
class="com.talkweb.web.action.LoginAction">
<result name="success">/admin/index.jsp</result>
<result name="failure">/index.jsp</result>
<result name="loginOut">/index.jsp</result>
</action> </package></struts>aplicationcontext.xml
?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">    <bean id = "StudentAdminImpl" class="com.talkweb.service.impl.StudentAdminImpl"></bean> <bean id="loginAction" class="com.talkweb.web.action.LoginAction" >
<property name="adminService" ref="StudentAdminImpl" />
</bean></beans>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- Struts2 filter,actionPackages定义扫描Action类的目录 -->
<servlet>
<servlet-name>autoLoadResourceObject</servlet-name>
<servlet-class>
com.talkweb.web.servlet.ResourceAutoLoader
</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet> <!-- structs2过滤器,负责与WEB容器的交互 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- structs2过滤器 -->
<!-- 配置Spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<!-- 指明spring配置文件在何处 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml</param-value>
    </context-param>

<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
login.action
package com.talkweb.web.action;import com.talkweb.model.Student;
import com.talkweb.service.BaseService;
import com.talkweb.web.commom.BaseAction;public class LoginAction extends BaseAction<Student>{ private static final long serialVersionUID = 1L; private BaseService adminService;

public Student getModel() {
// TODO Auto-generated method stub
return null;
}
/**
 * 登陆
 * @return
 * @throws Exception
 */
public String login(){
System.out.println("----------------");
String loginName = getRequestParmeterByTrim("loginName");
String password = getRequestParmeter("password");
this.getRequest().setAttribute("loginName",loginName);
if(null == loginName || "".equals(loginName)){
this.getRequest().setAttribute("msg","用户名不能为空!");
return "failure";
}else{
adminService.add();
return "success";
}
}
public BaseService getAdminService() {
return adminService;
}
public void setAdminService(BaseService adminService) {
this.adminService = adminService;
}

}

解决方案 »

  1.   

    你的action里的class="com.talkweb.web.action.LoginAction"应该跟spring的bean的id="loginAction"名字一样,就是说action里的class="com.talkweb.web.action.LoginAction"改成class="loginAction",你试试吧
      

  2.   

    http://topic.csdn.net/u/20110815/14/7c259888-1d1b-4be8-8a39-cfaffc416d66.html
      

  3.   

    你那是STRUT1啊  和2的整合一样吗
      

  4.   

    需要在strut.xml  的标签下<struts>
    加入 <constant name="struts.objectFactory" value="spring" />
    spring才能集成
      

  5.   

    ?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">    <bean id = "StudentAdminImpl" class="com.talkweb.service.impl.StudentAdminImpl"></bean>    <bean id="loginAction" class="com.talkweb.web.action.LoginAction" >
            <property name="adminService" ref="adminDao" />
        </bean>
     <bean id="adminService" class="com.talkweb.web.action.adminService" >
            <property name="adminDao" ref="dataBase" />
        </bean>
     <bean id="dataBase">    </bean></beans>在applictioncontext.xml中加入adminService的依赖对象,你adminService需要依赖adminDao...
    然后adminDao依赖dateBase,都要配置
      

  6.   

    有一个包你是不是没有添加 spring-struts-p打头的包你看下。是spring和struts集成的包
      

  7.   

    web.xml
    <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.opache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>strtus.xml<action id="路径名" class="spring中配置的servicbean的id" >
    按照你提供的代码写就是springContext.xml
    <!--  ben中id改为name -->
    <bean name="loginAction" class="com.talkweb.web.action.LoginAction" >
            <property name="adminService" ref="StudentAdminImpl" />
    </bean>struts.xml
    <!-- action中的class改为spring的bean的name -->
    <action name="login"
                class="loginAction">
                <result name="success">/admin/index.jsp</result>
                <result name="failure">/index.jsp</result>
                <result name="loginOut">/index.jsp</result>
    </action>