使用最新struts2(2.3.15.2),不能使用DMI动态调用方法

kangjiwww 2013-09-24 10:00:23
最新开始学习struts2,在官网上下载的最新的struts2(2.3.15.2), jar包,在使

用动态方法调用的时候老是报错,错误代码如下HTTP Status 404 - There is no

Action mapped for namespace [/] and action name [book!delBook] associated

with context path [/Struts2_0900_eg].但是导入struts-2.2.3.1的jar程序就能

正常动态方法调用,最新版的struts2到底怎么实现动态方法调用?代码如下

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">

<filter>
<filter-name>struts2</filter-name>
<filter-

class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilt

er</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


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>
<package name="struts2" extends="struts-default">
<action name="book"

class="com.softeem.struts.actions.BookAction">
<result type="redirect">/index.jsp</result>
</action>
</package>

</struts>


jsp页面
<body>
<a href="book!addBook.action">添加图书信息</a><br />
<a href="book!delBook.action">删除图书信息</a><br />
<a href="book!updateBook.action">修改图书信息</a><br />
<a href="book!readBook.action">查询图书信息</a><br />
</body>


Action类
package com.softeem.struts.actions;

import com.opensymphony.xwork2.ActionSupport;

public class BookAction extends ActionSupport {
public String addBook() {

System.out.println("添加图书成功!");
return SUCCESS;
}

public String delBook() {

System.out.println("删除图书成功!");
return SUCCESS;
}

public String updateBook() {

System.out.println("修改图书成功!");
return SUCCESS;
}

public String readBook() {

System.out.println("查询图书成功!");
return SUCCESS;
}
}
...全文
1268 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
F-PHantam 2016-05-31
  • 打赏
  • 举报
回复
路过 表示谢谢1楼 解决我一个困扰
qq_14942225 2014-08-08
  • 打赏
  • 举报
回复
好了,谢谢
coooliang 2014-05-12
  • 打赏
  • 举报
回复
<constant name="struts.enable.DynamicMethodInvocation" value="true" /> 打开动态方法调用。 可以,谢谢分享!!
aimeiKAKA 2014-04-28
  • 打赏
  • 举报
回复
一般正常情况下使用哪种方式通配符?actionName!方法名
信息屋 2014-03-15
  • 打赏
  • 举报
回复
这个问题困扰我好久了 终于解决了
wglpd 2013-12-23
  • 打赏
  • 举报
回复
原来是默认关闭的,都试了好久
yeyinqishi 2013-09-26
  • 打赏
  • 举报
回复
终于搞定了,这版本还真把动态方法改false了
大师兄吖 2013-09-24
  • 打赏
  • 举报
回复
在struts.xml中添加 <constant name="struts.enable.DynamicMethodInvocation" value="true" /> 打开动态方法调用。 动态方法调用官方推荐的做法是,使用通配符的形式。不要使用actionName!methodName 的方式。
kangjiwww 2013-09-24
  • 打赏
  • 举报
回复
太感谢了,struts2之前的版本动态方法调用默认是打开的,没想到2.3.15默认是关闭的

67,543

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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