关于初学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目录下。上网搜素发现了好多关于这个错误信息,但是都没有解决,请问那位大神给解答下:
...全文
144 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
star19860411 2017-01-10
  • 打赏
  • 举报
回复
引用 1 楼 qnmdcsdn 的回复:
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
struts.xml添上一句
+1
墨笙弘一 2017-01-10
  • 打赏
  • 举报
回复
你用了动态方法调用 应该按照楼上说的添加那句配置在struts.xml中,可以看看我博文中对于Struts2中DMI的笔记
  • 打赏
  • 举报
回复
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
struts.xml添上一句

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧