There is no Action mapped for namespace [/] and action name [struts2Test!test] associated with conte

来源:互联网 发布:怪物猎人p3雷狼数据 编辑:程序博客网 时间:2024/06/05 04:22

1、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<!-- <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> -->


<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring配置文件位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml,classpath:spring-hibernate.xml</param-value>
</context-param>


<!-- 防止spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>


<!-- openSessionInView配置 -->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>


<!-- Struts2的核心过滤器配置 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,../../resources/struts.xml</param-value>
</init-param>
</filter>
<!-- Struts2过滤器拦截所有的.action请求 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>


<!-- druid监控页面,使用${pageContext.request.contextPath}/druid/index.html访问 -->
<servlet>
<servlet-name>druidStatView</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>druidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
</web-app>


2、struts.xml

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 指定由spring负责action对象的创建 -->
<constant name="struts.objectFactory" value="spring" />
<!-- 所有匹配*.action的请求都由struts2处理 -->
<constant name="struts.action.extension" value="action" />
<!-- 是否启用开发模式(开发时设置为true,发布到生产环境后设置为false) -->
<constant name="struts.devMode" value="true" />
<!-- struts配置文件改动后,是否重新加载(开发时设置为true,发布到生产环境后设置为false) -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 设置浏览器是否缓存静态内容(开发时设置为false,发布到生产环境后设置为true) -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 请求参数的编码方式 -->
<constant name="struts.i18n.encoding" value="utf-8" />
<!-- 每次HTTP请求系统都重新加载资源文件,有助于开发(开发时设置为true,发布到生产环境后设置为false) -->
<constant name="struts.i18n.reload" value="true" />
<!-- 文件上传最大值 -->
<constant name="struts.multipart.maxSize" value="104857600" />
<!-- 让struts2支持动态方法调用,使用叹号访问方法 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- Action名称中是否还是用斜线 -->
<constant name="struts.enable.SlashesInActionNames" value="false" />
<!-- 允许标签中使用表达式语法 -->
<constant name="struts.tag.altSyntax" value="true" />
<!-- 对于WebLogic,Orion,OC4J此属性应该设置成true -->
<constant name="struts.dispatcher.parametersWorkaround" value="false" />
<package name="basePackage" namespace="/" extends="struts-default">
</package>
</struts>

3、action代码

package com.zy.action;


import java.util.Date;
import java.util.UUID;


import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;


import com.zy.model.User;
import com.zy.service.UserServiceI;


@ParentPackage("basePackage")
// 使用convention-plugin插件提供的@Action注解将一个普通java类标注为一个可以处理用户请求的Action,Action的名字为struts2Test
@Action(value = "struts2Test")
// 使用convention-plugin插件提供的@Namespace注解为这个Action指定一个命名空间
@Namespace("/")
public class TestAction {
@Autowired
private UserServiceI userServiceI;


public void test() {
System.out.println("进入TestAction");
userServiceI.test();
}


public void saveUser() {
User user = new User();
user.setId(UUID.randomUUID().toString().replaceAll("-", ""));
user.setName("Ray");
user.setPassword("123456");
user.setCreatedatetime(new Date());
userServiceI.save(user);
}
}


4、url

http://localhost:7788/zySystem/struts2Test!test.action

5、error message

There is no Action mapped for namespace [/] and action name [struts2Test!test] associated with context path [/zySystem].

找了好久,还是没能解决,希望各位大神能够帮忙哈!不胜感激!


阅读全文
0 0
原创粉丝点击