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

J2EE 码拜 9年前 (2015-04-17) 1214次浏览 0个评论

最新开始学习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;
	}
}
使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
40分
在struts.xml中添加
<constant name=”struts.enable.DynamicMethodInvocation” value=”true” /> 
打开动态方法调用。
动态方法调用官方推荐的做法是,使用通配符的形式。不要使用actionName!methodName
的方式。
使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
太感谢了,struts2之前的版本动态方法调用默认是打开的,没想到2.3.15默认是关闭的
使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
终于搞定了,这版本还真把动态方法改false了
使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
原来是默认关闭的,都试了好久
使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
这个问题困扰我好久了  终于解决了
使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
  一般正常情况下使用哪种方式通配符?actionName!方法名
使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
<constant name=”struts.enable.DynamicMethodInvocation” value=”true” /> 
打开动态方法调用。

可以,谢谢分享!

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

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!