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. Python利用脚本2.x到3自动转换

    本文介绍一下在windows 10 环境下如何使用这个工具: 1)首先要先安装好python3,可到官网下载https://www.python.org/ 2)使用Windows 命令提示符(cmd) ...

  2. SerializeHelper

    using System; using System.Collections.Generic; using System.Configuration; using System.IO; using S ...

  3. MySQL--局域网、外网访问MySQL

    一.局域网.外网访问 1. 打开CMD,导航到当前MySQL的bin路径,如下图: 2. 访问MySQL:输入MySQL -u root -p,点击Enter键,即可看到密码输入框: 输入密码,点需E ...

  4. Android Notification通知栏的使用,通知栏在Android8.0系统不显示的问题;

    1.正常使用通知栏: /** * 创建通知栏管理工具 */ NotificationManager notificationManager = (NotificationManager) getSys ...

  5. 图解RabbitMQ

    花点时间重新把rabbitMQ的整体流程粗略的梳理了一遍,便于理解.总体来说,消息产生者->queue->消息消费者可以图解如下: 文字解说:消息产生者 producter 和 consu ...

  6. git 使用教程(二)

    MyEclipse下使用GitHub方法(Eclipse同理) 原创 2016年01月04日 20:30:25 标签: myeclipse / 软件 / git / github / eclipse ...

  7. day3----编码-集合-深浅copy-文件操作-函数初识

    本文档主要内容: 一 编码 二 集合 三 深浅copy 四 文件操作 五 函数初识 首先,我们来看看两个字符串的比较 打开cmd,进入dos界面 >>>a='xingchen@' & ...

  8. CMD下的netstat命令

    查询端口启用情况 netstat -ano|findstr 80

  9. 52.纯 CSS 创作一个小球绕着圆环盘旋的动画

    原文地址:https://segmentfault.com/a/1190000015295466 感想:重点在小球绕环转动. HTML code: <div class="contai ...

  10. java 正则 贪婪匹配 匹配sql语句中的引号内容

    public class Demo { public static void main(String[] args) { String sql1 = "use test;select * f ...