首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

struts2找不到action 求解.该怎么处理

2013-07-20 
struts2找不到action 求解.....web.xml[/?xml version1.0 encodingUTF-8?web-app version2.5

struts2找不到action 求解.....
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">

    <display-name>example</display-name>

    
    <!-- struts2 过滤器 -->
<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>

<!-- spring的监听器,以便在启动时就自动加载spring的配置 -->
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<!-- spring的应用上下文 -->
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:config/applicationContext.xml,classpath*:config/applicationContext-*.xml</param-value>
    </context-param>

    <welcome-file-list>
        <welcome-file>user.jsp</welcome-file>
    </welcome-file-list>

</web-app>
code]

struts.xml
[code=text]<?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>

    <package name="default" extends="struts-default">
    <result-types>
    <result-type name="json" class="com.googlecode.jsonplugin.JSONResult"></result-type>
    </result-types>   
    
   <action name="allUsers" class="userAction" method="selectAll">
<!--         <result type="json"> -->


<!--         </result> -->
        <result name="all" >/user.jsp</result>
        </action>
<!--         <action name="fetchUserInfo" class="userManageAction" method="fetchUserInfo"> -->
<!--         <result type="json"></result> -->
<!--         </action> -->
<!--         <action name="addUser" class="userManageAction" method="addUser"></action> -->
<!--         <action name="updateUser" class="userManageAction" method="updateUser"></action> -->
<!--         <action name="deleteUsers" class="userManageAction" method="deleteUsers"></action> -->
    </package>
    
</struts>


启动不报错  访问allUsers.action报错
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

There is no Action mapped for namespace / and action name allUsers. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:497)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.
这是action的代码
public class UserAction extends BaseAction {
   private List<User> users;
       private IUserService userService;

public List<User> getUsers() {
return users;
}

public void setUsers(List<User> users) {
this.users = users;
}

public IUserService getUserService() {
return userService;
}

public void setUserService(IUserService userService) {


this.userService = userService;
}
public String selectAll(){
users=userService.findAllUser();

return "all";
}


[解决办法]
楼主没声明struts2的对象工厂为spring
在struts.xml里加上<constant name="struts.objectFactory" value="spring" />
[解决办法]
引用:
楼主没声明struts2的对象工厂为spring
在struts.xml里加上<constant name="struts.objectFactory" value="spring" />

很可能是这个问题,lz在struts的配置文件中添加这一句试试看。

热点排行