一、method参数

action

package com.pb.web.action;

public class HourseAction {

    public String add(){
System.out.println("执行添加操作!");
return "success";
}
public String update(){
System.out.println("执行更新操作!");
return "success";
}
public String delete(){
System.out.println("执行删除操作!");
return "success";
} }

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> <!-- <constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results>
<result name="error">/error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings> <action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package> <include file="example.xml"/> --> <!-- Add packages here -->
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="hourse_add" class="com.pb.web.action.HourseAction" method="add">
<result>
addsuccess.jsp
</result>
</action>
<action name="hourse_update" class="com.pb.web.action.HourseAction" method="update">
<result>
updatesuccess.jsp
</result>
</action>
<action name="hourse_del" class="com.pb.web.action.HourseAction" method="delete">
<result>
deletesuccess.jsp
</result>
</action>
</package>
</struts>

默认action配置

<!--默认action  -->
<default-action-ref name="index" />
<action name="index">
<result>
index.jsp
</result>
</action>

二、使用动态方法调用

package com.pb.web.action;

public class UserAction {

    public String add(){
System.out.println("执行添加操作!");
return "success";
}
public String update(){
System.out.println("执行更新操作!");
return "success";
}
public String delete(){
System.out.println("执行删除操作!");
return "success";
}
}

struts.xml

<package name="default" namespace="/" extends="struts-default">
<action name="user" class="com.pb.web.action.UserAction">
<result>
userSuccess.jsp
</result>
</action>

页面

<!--  使用感叹号,调用指定方法-->
<form action="user!add">
<input type="submit" value="添加"/>
</form>
<form action="user!update">
<input type="submit" value="更新"/>
</form>
<form action="user!delete">
<input type="submit" value="删除"/>
</form>

另一种写法

<!--  使用感叹号,调用指定方法-->
<form action="user!add.action">
<input type="submit" value="添加"/>
</form>
<form action="user!update.action">
<input type="submit" value="更新"/>
</form>
<form action="user!delete.action">
<input type="submit" value="删除"/>
</form>

三、使用通配符简化配置

action

package com.pb.web.action;

public class HourseAction {

    public String add(){
System.out.println("执行添加操作!");
return "success";
}
public String update(){
System.out.println("执行更新操作!");
return "success";
}
public String delete(){
System.out.println("执行删除操作!");
return "success";
} }

struts.xml

<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="hourse_*" class="com.pb.web.action.HourseAction" method="{1}">
<result>
{1}success.jsp
</result>
</action>
</package>

页面

<%@ 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>Insert title here</title>
</head>
<body>
<form action="hourse_add">
<input type="submit" value="添加"/>
</form>
<form action="hourse_update">
<input type="submit" value="更新"/>
</form>
<form action="hourse_delete">
<input type="submit" value="删除"/>
</form>
</body>
</html>

Struts2(五)Action二配置的更多相关文章

  1. Struts2学习笔记二 配置详解

    Struts2执行流程 1.简单执行流程,如下所示: 在浏览器输入请求地址,首先会被过滤器处理,然后查找主配置文件,然后根据地址栏中输入的/hello去每个package中查找为/hello的name ...

  2. java之struts2的action优化配置

    当一个Action处理类中处理多个业务时,action的配置 文件将会急剧增加,导致配置文件很臃肿的问题. struts2提供了两种方案来解决这个问题.一种是动态方法调用,另一种是使用通配符来配置Ac ...

  3. Struts2学习笔记(二)——配置详解

    1.Struts2配置文件加载顺序: default.properties(默认常量配置) struts-default.xml(默认配置文件,主要配置bean和拦截器) struts-plugin. ...

  4. Struts2(五)常量的配置

    Struts2 常量大多在 默认的配置文件中已经配置好,但根据用户的需求不同,开发的要求不同,需要修改这些常量值,修改的方法就是在配置的文件对常量进行重新配置 在struts.xml 文件中使用< ...

  5. Struts2(五.用户注册的实现及整合Action的配置方法)

    一.用户注册功能 register.jsp页面 若是jquery ajax方式提交给action,还要回到jquery,控制权在jquery若是表单方式提交给action,控制权交给action &l ...

  6. Struts2基础学习(二)—Action

    一.ActionSupport      为了让用户开发的Action类更加规范,Struts2提供了一个Action接口,这个接口定义了Struts2的Action处理类应该实现的规范.下面是标准A ...

  7. Struts2框架学习(二) Action

    Struts2框架学习(二) Action Struts2框架中的Action类是一个单独的javabean对象.不像Struts1中还要去继承HttpServlet,耦合度减小了. 1,流程 拦截器 ...

  8. struts2 之 Action的优化配置

    总结:struts2种action的配置文件会随着业务的增加而增加,导致配置文件膨胀.struts2中提供了三种方案来解决这个问题: 1. 动态方法调用来实现. 2. 通配符配置来解决. 3. 使用注 ...

  9. struts2 ,web.xml中配置为/*.action,运行报错Invalid <url-pattern> /*.action in filter mapp

    首先,修改成: <filter-mapping>  <filter-name>struts2</filter-name>  <url-pattern>/ ...

随机推荐

  1. CodeForces 81D.Polycarp's Picture Gallery 乱搞

    D. Polycarp's Picture Gallery time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  2. Windows下openssl安装及使用

    配置过程中需要生成一些mak文件,这些生成代码用perl脚本生成,所以要安装一个ActivePerl. 网址: http://www.activestate.com/activeperl/ 下载后直接 ...

  3. Spring @Value 用法小结,#与$的区别

    20161016更新:这货其实是SpEL的功能,来这里看看吧: Spring 4 官方文档学习(五)核心技术之SpEL 起因 一直的用法是 @Value("${jdbc.driverClas ...

  4. HDU 2686 Matrix(最大费用流)

    Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  5. ASP.NET浏览器跨域

    转载:http://www.cnblogs.com/alvinwei1024/p/4626054.html 什么是跨域? 访问同源的资源是被浏览器允许的,但是如果访问不同源的资源,浏览器默认是不允许的 ...

  6. JSPGen4 自学路线图

  7. SpringBoot 使用小技巧合集

    原文:https://my.oschina.net/xiedeshou/blog/1926191 设置网站图标 原来我们在使用tomcat开发时,设置网站图片时,即icon图标时,一般都是直接替换ro ...

  8. Spring加载Hibernate 映射的几种方式及区别

    LocalSessionFactoryBean有好几个属性用来查找hibernate映射文件: mappingResources.mappingLocations.mappingDirectoryLo ...

  9. POPSpring动画参数详解

    POPSpring动画参数详解 效果 源码 https://github.com/YouXianMing/Animations // // POPSpringParameterController.m ...

  10. WebService—CXF整合Spring实现接口发布和调用过程

    一.CXF整合Spring实现接口发布 发布过程如下: 1.引入jar包(基于maven管理) <!-- cxf --> <dependency> <groupId> ...