我们在配置一个action的时候,为了避免下Action类的每个方法都映射成一个action 我们可以这样配置:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="*User" method="{1}" class="vaannila.UserAction">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
以前我们是:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="User" class="vaannila.UserAction">
<result name="success">/success.jsp</result>
</action>
<action name="addUser" method="add" class="vaannila.UserAction">
<result name="success">/success.jsp</result>
</action>
<action name="updateUser" method="update" class="vaannila.UserAction">
<result name="success">/success.jsp</result>
</action>
<action name="deleteUser" method="delete" class="vaannila.UserAction">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
写了比较多的重复代码,现在struts2支持动态方法调用,以通配符的形式来查找对应的方法。
下面我们写java代码
package vaannila;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
private String message;
public String execute()
{
message = "Inside execute method";
return SUCCESS;
}
public String add()
{
message = "Inside add method";
return SUCCESS;
}
public String update()
{
message = "Inside update method";
return SUCCESS;
}
public String delete()
{
message = "Inside delete method";
return SUCCESS;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
最后就是我们访问action的url怎么写呢?
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<s:form action="User" >
<s:submit />
<s:submit action="addUser" value="Add" />
<s:submit action="updateUser" value="Update" />
<s:submit action="deleteUser" value="Delete" />
</s:form>
</body>
</html>
addUser匹配在strut2中配置的*User,那么add将会被作为了方法的名字到UserAction查找叫add的方法。这样就实现了动态方法的关系映射。
分享到:
相关推荐
1、升级所需要的jar(见附件): freemarker-2.3.22.jar ognl-3.0.19.jar ... <constant name="struts.enable.DynamicMethodInvocation" value="true"/> 这两行请不要加在外边。“加在这里”</struts>
method invocation and dispatch. After reading this part, you will understand the advanced features of Ice and how to effectively use them to find the correct trade-off between performance and resource...
struts.devMode=false struts.enable.DynamicMethodInvocation=true struts.i18n.reload=true struts.ui.theme=simple struts.locale=zh_CN struts.i18n.encoding=UTF-8 struts.serve.static.browserCache=false ...
struts.enable.DynamicMethodInvocation Allows one to disable dynamic method invocation from the URL 允许动态方法调用 struts.freemarker.manager.classname The org.apache.struts2.views.freemarker....
Allows IDispatch dynamic method invocation through Variant Assignment of script functions to Delphi events Uses byte code as an intermediate format and allows storing and reloading compiled ...
struts.enable.DynamicMethodInvocation 该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true.如果需要关闭动态方法调用,则可设置该属性为false. struts.enable.SlashesInActionNames 该属性设置Struts ...
struts.enable.DynamicMethodInvocation 该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该属性为false。 struts.enable.SlashesInActionNames 该属性...
go程序设计语言 Contents Preface................................................................................................................................. xix PART 1—WHY LEARN GO—GETTING ...
The Way to Go,: A Thorough Introduction to the Go Programming Language 英文书籍,已Cross the wall,从Google获得书中源代码,分享一下。喜欢请购买正版。 目录如下: Contents Preface......................
Other Forms of Method Invocation The invokespecial instruction invokespecial and () invokespecial and Private Methods invokespecial and super The invokeinterface Instruction Invocation ...
捕获异常并记录异常的拦截器可以非常简单地实现为: // Intercept() is the single method of IInterceptor.public void Intercept ( IInvocation invocation ){ try { invocation . Proceed (); } catch ( ...
1.6.6.2 Method body and local variables 16 1.6.6.3 Static and instance methods 17 1.6.6.4 Virtual, override, and abstract methods 18 1.6.6.5 Method overloading 20 1.6.7 Other function members 21 1.6....
Method and Constructor Constraint Chapter 12 : Java Transaction User-Managed Transactions Container-Managed Transactions @TransactionScoped Chapter 13 : Java Persistence Entities ...
11.11 Dynamic Invocation L2 150 Exercises 153 12 HIGHER-ORDER FUNCTIONS L1 157 12.1 Functions as Values 157 12.2 Anonymous Functions 159 12.3 Functions with Function Parameters 160 12.4 Parameter ...
control method attempts to create 2 objects of the same name. This once again returns AE_ALREADY_EXISTS. When this exception occurs, it invokes the mechanism that will dynamically serialize the ...
5.1 Dynamic Version of State Identification by UOFC 5.2 Data Fusion Appendiex 1: The Fast Wavelet Transform Appendix 2: Multichannel Model-Based Decomposition by Matching Pursuit Appendix 3:...
Defines the Remote Method Invocation (RMI) API. java.scripting Defines the Scripting API. java.se Defines the core Java SE API. java.se.ee Defines the full API of the Java SE Platform. java....
Remote Method Invocation (RMI) RMI-IIOP Scripting for the Java Platform User Interface Libraries 2D Graphics and Imaging Accessibility Abstract Window Toolkit (AWT) Drag-and-Drop Data ...
Invocation H Command-Line Arguments H Program Layout H G Data Types Scalars H Arrays H Associative Arrays H File Handles H G Special Variables Environment Variables H Program Arguments H ...
2.5.3 TCAP Operation Invocation Example 44 2.6 User-Level Application Parts: MAP, INAP, CAMEL 45 2.6.1 User Part Mapping onto TCAP: MAP Example 45 2.6.2 Routing Design 48 2.6.3 Service-Oriented Design...