Structs复习 ActionMethod
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的更多相关文章
- Structs复习 开始 第一个helloworld项目
大体已经学完ssh了 感觉一起做一个项目有点难 计划先用一下独立的Structs 然后再把数据库操作换成hibernate 然后在用Spring 整合 计划用10天左右吧 但今天开始用Struct ...
- Structs复习 Structs标签
如果类型是object Structs会把它默认解析为OGNL表达式 想取字符串的话就 ‘’ ‘ ’ ‘’ jar包 web.xml. <?xml version="1.0" ...
- Structs复习 OGNL
Dominmodel只有传 User.age 类似的这种Structs才能帮创建对象 Dominmodel User里必须有空的构造方法 OGNL:OBJECT GRAPHIC NAVAGATION ...
- Structs复习 Result第二部分
1.动态结果 2.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...
- Structs复习 Result第一部分
Jar包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&q ...
- Structs复习 访问web元素
Structs帮我们在action和http里建立了联系 主要有四种方式 我们主要用第二种(IOC 依赖容器注入 ) Jar包 web.XML <?xml version="1.0&q ...
- Structs复习 Action传递参数
Structs传递参数通常有三种方式 下面我来一个个介绍 1.属性 Jar包 web.xml <?xml version="1.0" encoding="UTF-8 ...
- Structs复习 通配符
1.jar包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...
- Structs复习 Path问题
Path问题相对复杂 主要是路劲问题 但结论很简单 就是统一使用绝对路径 jar包 web.xml <?xml version="1.0" encoding="UT ...
随机推荐
- Elasticsearch的JavaAPI
获取客户端对象 public class App { private TransportClient client; //获取客户端对象 @Before public void getClinet() ...
- Java - 15 Java 正则表达式
Java 正则表达式 正则表达式定义了字符串的模式. 正则表达式可以用来搜索.编辑或处理文本. 正则表达式并不仅限于某一种语言,但是在每种语言中有细微的差别. Java正则表达式和Perl的是最为相似 ...
- linux:安装mysql管理工具phpmyadmin
1.下载phpmyadmin,下载地址:http://www.phpmyadmin.net/ 2.解压到/var/www/html/phpmyadmin/ 3.修改配置 cd /var/www/htm ...
- MySQL字符集及校对规则的理解
阅读目录:MySQL的字符集和校对规则 MySQL的字符集 MySQL与字符集 正确使用字符集 MySQL客户端与字符集 字符集编码转换原理 字符集常见处理操作 字符集的正确实践 MySQL的校对 ...
- ES6学习笔记<五> Module的操作——import、export、as
import export 这两个家伙对应的就是es6自己的 module功能. 我们之前写的Javascript一直都没有模块化的体系,无法将一个庞大的js工程拆分成一个个功能相对独立但相互依赖的小 ...
- 【Eclipse】Eclipse 安装 SVN 插件的三种方法
最近使用Eclipse时,修改代码总是看不到变化,不知道那个文件修改了,想起了当时开发C++的时候,有相关的插件,于是乎就网搜了下,果然有Eclipse的SVN配置. 接下来,我采用了第二种方式,一起 ...
- django-chunks文件
with open(file_save_path, 'wb') as f: for chunk in file_content.chunks(): f.write(chunk)
- C# sqlserver winform
//public static readonly string LocalSqlServer = System.Configuration.ConfigurationManager.AppSettin ...
- SAP HANA数据库架构部署方法
HANA作为内存数据库,在实现高性能访问的同时,必须也要有稳定的架构,今天我们就来看看企业部署SAP HANA时应该如何来设计数据库的架构. HANA数据库在安装时,有以下几种选择方法,为方便大家理解 ...
- pom格式
参考: https://www.jianshu.com/p/0e3a1f9c9ce7 https://blog.csdn.net/u012152619/article/details/51485297 ...