我是新手, 刚学Struts2 和 spring。
用的是Struts2.1.8 、 spring2.5
好心人帮忙解决一下,不胜感谢。这是浏览器上显示的错误:Struts Problem Report
Struts has detected an unhandled exception: Messages: loginAction 
Unable to instantiate Action, loginAction, defined for 'login' in namespace '/'loginAction 
 
File: org/apache/catalina/loader/WebappClassLoader.java 
Line number: 1,358 以下是代码:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

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

<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>
struts.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.devMode" value="true" />
    <package name="strut2" extends="struts-default" >
        <action name="login" class="loginAction">
            <result name="success">/result.jsp</result>
            <result name="input">/login.jsp</result>
        </action>
    </package>
</struts>
applicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="loginService" class="com.ican.web.dao.impl.LoginServiceImpl" scope="prototype"></bean>

<bean id="loginAction" class="com.ican.web.struts2.LoginAction" scope="prototype">
<property name="iLoginService" ref="loginService"></property>
</bean>
</beans>login.jsp<s:form action="login" method="post" >
     <s:textfield name="username" label="用户名"></s:textfield><br />
     <s:password name="password" label="密 码"></s:password><br />
     <s:submit name="submit"  value="登陆"></s:submit>
</s:form>

解决方案 »

  1.   

    WebappClassLoader
    行号都告你了
      

  2.   

    web.xml里面少了这
    <constant name="struts.objectFactory" value="spring"/>
      

  3.   

    http://www.blogjava.net/xcp/archive/2008/09/13/s2s.html
    给楼主找了个例子 
      

  4.   

    楼主好好看看你那struts.xml中根本就没有给包加命名空间呀!
      

  5.   

    命名空间的问题,
    <action name="login" class="com.ican.web.struts2.LoginAction">
      

  6.   

    感谢各位, 我自己做出来了, 虽然不知道是哪里出问题了。 
    下面我把我的代码贴上来。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.objectFactory" value="spring" />
    <package name="default" extends="struts-default"> <action name="Login" class="loginAction">
    <result name="success">/result.jsp</result>
    <result name="input">/login.jsp</result>
    </action> </package>
    </struts>
    applicationContext.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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean id="UserManager" class="com.ican.web.dao.impl.UserManagerImpl" scope="prototype"></bean>
    <bean id="loginAction" class="com.ican.web.struts2.LoginAction" scope="prototype">
    <property name="iUserManager" ref="UserManager"></property>
    </bean>
    </beans>web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>login.jsp
    <%@ page language="java" contentType="text/html; charset=GB18030"
        pageEncoding="GB18030"%>
       <%@ taglib prefix="s" uri="/struts-tags" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
    <title>Insert title here</title>
    </head>
    <body>
    <s:form action="Login" method="post">
    <s:textfield name="username" label="用户名" />
    <s:password name="password" label="密 码" />
    <s:submit label="submit" value="登陆" ></s:submit>
    </s:form>
    </body>
    </html>struts.properties
    struts.objectFactory = spring