action在执行的是时候 可以不执行excute方法 可以由自己制定 可以在action标签里指定  也可以在方法里动态指定 推荐使用后者

jar包

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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <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>

Struct.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>
<constant name="struts.devMode" value="true" />
<package name="user" extends="struts-default" namespace="/user">
<action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add">
<result>/user_add_success.jsp</result>
</action> <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
<result>/user_add_success.jsp</result>
</action>
</package>
</struts>

UserAction.java

package com.bjsxt.struts2.user.action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {
public String add() {
return SUCCESS;
} }

index.jsp

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%> <% String context = request.getContextPath(); %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>Insert title here</title>
</head>
<body>
Action执行的时候并不一定要执行execute方法<br />
可以在配置文件中配置Action的时候用method=来指定执行哪个方法
也可以在url地址中动态指定(动态方法调用DMI)(推荐)<br />
<a href="<%=context %>/user/userAdd">添加用户</a>
<br />
<a href="<%=context %>/user/user!add">添加用户</a>
<br />
前者会产生太多的action,所以不推荐使用 </body>
</html>

输入

http://localhost:6666/Struts2_0500_ActionMethod/index.jsp

点击第一个

点击第二个

http://localhost:6666/Struts2_0500_ActionMethod/user/user!add

推荐使用第二种在网志里动态制定

Structs复习 ActionMethod的更多相关文章

  1. Structs复习 开始 第一个helloworld项目

    大体已经学完ssh了  感觉一起做一个项目有点难 计划先用一下独立的Structs 然后再把数据库操作换成hibernate  然后在用Spring 整合 计划用10天左右吧 但今天开始用Struct ...

  2. Structs复习 Structs标签

    如果类型是object Structs会把它默认解析为OGNL表达式 想取字符串的话就 ‘’ ‘ ’ ‘’ jar包 web.xml. <?xml version="1.0" ...

  3. Structs复习 OGNL

    Dominmodel只有传 User.age 类似的这种Structs才能帮创建对象 Dominmodel User里必须有空的构造方法 OGNL:OBJECT GRAPHIC NAVAGATION ...

  4. Structs复习 Result第二部分

    1.动态结果 2.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...

  5. Structs复习 Result第一部分

    Jar包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&q ...

  6. Structs复习 访问web元素

    Structs帮我们在action和http里建立了联系 主要有四种方式 我们主要用第二种(IOC 依赖容器注入 ) Jar包 web.XML <?xml version="1.0&q ...

  7. Structs复习 Action传递参数

    Structs传递参数通常有三种方式 下面我来一个个介绍 1.属性 Jar包 web.xml <?xml version="1.0" encoding="UTF-8 ...

  8. Structs复习 通配符

    1.jar包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  9. Structs复习 Path问题

    Path问题相对复杂 主要是路劲问题 但结论很简单 就是统一使用绝对路径 jar包 web.xml <?xml version="1.0" encoding="UT ...

随机推荐

  1. 获取Android文件路径

    Environment.getDataDirectory().getPath() : /data Environment.getDownloadCacheDirectory().getPath() : ...

  2. Web api Json 接受的参数类型为父类,自动序列化为子类的过程

    场景: public abstract class JsonCreationConverter<T> : JsonConverter { /// <summary> /// t ...

  3. 让WordPress支持google AMP

    1.关于AMP 在移动互联网的时代,尽管网站响应式设计可以满足多屏(pc.手机.ipad等)浏览,但google在2015年10月推出了更快移动页面访问速度的技术-Accelerated Mobile ...

  4. 04 bash程序的基本特性

    我们知道Linux系统有两种操作方式,一种为GUI的图形界面化管理方式,其中图形程序常见的有Gnome.KDE.xfce:另一种管理方式就是就是GLI的命令行管理方式,而命令行的管理方式就是通过she ...

  5. ZooKeeper的安装和API

    Zookeeper的分布式安装和API介绍: 安装教程 在datanode1.datanode2和datanode3三个节点上部署Zookeeper. 步骤 解压zookeeper安装包到/opt/m ...

  6. Solr之精确、匹配、排序、模糊查询-yellowcong

    Solr查询数据,其实下面一堆的参数,我也没有做测试,只是转载过来了,我大概只用了高亮.排序.查询.分页,其他的好像没有用过,以后用再来查 一.基本查询 参数 意义 q 查询的关键字,此参数最为重要, ...

  7. vue-demo

    github地址:  https://github.com/TingtingYin/vue-demo

  8. SVG 学习<三>渐变

    目录 SVG 学习<一>基础图形及线段 SVG 学习<二>进阶 SVG世界,视野,视窗 stroke属性 svg分组 SVG 学习<三>渐变 SVG 学习<四 ...

  9. win7 CMD登录本机MySQL数据库管理

  10. SVG:中国地图

    中国地图 <svg height="578" version="1.1" width="718" xmlns="http:/ ...