关于初学STRUTS中遇到的问题:There is no Action mapped for namespace ......
熊黄酒_H 2017-01-09 10:50:41 package com.lyq.action;
import com.opensymphony.xwork2.ActionSupport;
/**
* 用户Action
* @author Li Yongqiang
*/
public class UserAction extends ActionSupport {
private static final long serialVersionUID = 1L;
// 提示信息
private String info;
// 添加用户信息
public String add() throws Exception{
info = "添加用户信息";
return "add";
}
// 更新用户信息
public String update() throws Exception{
info = "更新用户信息";
return "update";
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}
-------------------------------------------struts.xml-----------------------------------------
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 声明包 -->
<package name="myPackage" extends="struts-default" >
<!-- 定义action -->
<action name="UserAction" class="com.lyq.action.UserAction" >
<!-- 添加成功的映射页面 -->
<result name="add">user_add.jsp</result>
<!-- 更新成功的映射页面 -->
<result name="update">user_update.jsp</result>
</action>
</package>
</struts>
------------------------------index.jsp------------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>首页</title>
</head>
<body>
<a href="userAction!add">添加用户</a>
<br>
<a href="userAction!update">更新用户</a>
</body>
</html>
-------------------------------------------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>
<!-- struts2过滤器 -->
<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>
</web-app>
错误:
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [userAction!update] associated with context path [/STRUTS_TEXT].
type Status report
message There is no Action mapped for namespace [/] and action name [userAction!update] associated with context path [/STRUTS_TEXT].
description The requested resource (There is no Action mapped for namespace [/] and action name [userAction!update] associated with context path [/STRUTS_TEXT].) is not available.
Apache Tomcat/6.0.13
struts.xml 放置在 src目录下。上网搜素发现了好多关于这个错误信息,但是都没有解决,请问那位大神给解答下: