Struts2中关于Action mapped for namespace 的问题

Struts2中关于" There is no Action mapped for namespace [/role] and action name [roleAction!list] assoc"


新手搭建了个ssh框架项目,遇到了这个问题,也不知道哪里出错,希望大家帮忙看下

遇到问题到网上寻找解决办法,一直没有解决我的问题

struts2+spring4.2+hibernate5

项目名称是  EnxinOA



用这个地址访问   http://localhost:8080/EnxinOA/role/list.action

出现这个结果

HTTP Status 404 - /EnxinOA/WEB-INF/content/role/jsp/roleAction/list.jsp



用这个地址访问http://localhost:8080/EnxinOA/role/roleAction!list.action

是这个结果

HTTP Status 404 - There is no Action mapped for namespace [/role] and action name [roleAction!list] associated with context path [/EnxinOA].

弄了半天也没弄好,请大家指点一下


目录结构



RoleAction代码如下

@Controller("roleAction")
@Scope("prototype")
@ParentPackage("struts-default")
@Namespace("/role")
@Results({
	@Result(name="addUI",type="dispatcher",location="jsp/roleAction/addUI.jsp"),
	@Result(name="list",type="dispatcher",location="jsp/roleAction/list.jsp")
})
public class RoleAction extends ActionSupport  implements ModelDriven<Role> {

	private Role role= new Role();
	private List<Role> roles;
	
	@Resource(name="roleService")
	private IRoleService roleService;
	
	@Override
	public Role getModel() {
		return role;
	}
	
	/** 列表 */
	@Action("list")
	public String list() throws Exception {
		//DetachedCriteria dCriteria = DetachedCriteria.forClass(Role.class);
		//roles = roleService.findAllRole(dCriteria);
		System.out.println("list开始。。。。。。");
		return "list";
	}
	
	/** 添加 */
	@Action("addUI")
	public String addUI() throws Exception {
		return "addUI";
	}
	
	/** 添加 */
	public String add() throws Exception {
		return "toList";
	}
	
	/** 删除 */
	public String delete() throws Exception {
		//roleService.delete();
		return "toList";
	}
	
	/** 修改 */
	public String editUI() throws Exception {
		return "editUI";
	}
	
	/** 修改 */
	public String edit() throws Exception {
		return "toList";
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	
}

web.xml的代码如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>EnxinOA</display-name>
  
  <!-- 配置struts2的主过滤器,使项目可以使用sturts2框架 -->
  <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>/*</url-pattern>
  </filter-mapping>
  
  <!-- 配置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.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
</web-app>

spring的配置文件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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

	<!-- 配置spring创建容器时候要扫描注解的包 -->
	<context:component-scan base-package="com.enxin.oa.*"></context:component-scan>

	<!-- 配置HibernateTemplate -->
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<!-- 配置sessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<property name="hibernateProperties">
			<props>
				<!-- 告诉hibernate使用数据库连接池,不使用jdbc -->
				<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
				<!-- 数据库方言 -->
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<!-- 是否显示hibernate生产的sql语句 -->
				<prop key="hibernate.show_sql">true</prop>
				<!-- 是否用格式化输出sql语句到控制台 -->
				<prop key="hibernate.format_sql">false</prop>
				<!-- 配置hibernate采用何种方式生成ddl语句 -->
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<!-- 把session和线程绑定,从而实现一个线程只有一个session -->
				<prop key="hibernate.current_session_context_calss">org.springframework.orm.hibernate5.SpringSessionContext</prop>
			</props>
		</property>
		
		<!-- 扫描有注解实体类生成数据库表格 -->
		<property name="packagesToScan">
			<array>
				<value>com.enxin.oa.domain</value>
			</array>
		</property>
	</bean>

	<!-- 配置数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
		<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/enxinoa?useUnicode=true&characterEncoding=utf-8&useSSL=true"></property>	
		<property name="user" value="root"></property>
		<property name="password" value="root"></property>
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<!-- 开启spring对注解事务的支持 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
	
	<!-- 在业务层需要使用事务的地方使用@Transactional注解 -->


</beans>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值