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 ...
随机推荐
- 使用gulp压缩js详细步骤笔记
先要安装nodejs,初始化项目配置文件package.json,根据情况输入配置参数 npm init test command: git repository: keywords: author: ...
- Hibernate的hql语句save,update方法不执行
Hibernate的hql语句save,update方法不执行 可能出现的原因问题: 未进行事务管理 需要进行xml事务配置或者注解方式的事务配置
- Google App Engine10年,支持更多你喜欢的编程语言
2008年4月7日google推出Google App Engine(GAE),时间过得真快,10年过去了,2010年3月google退出中国,一转眼也过去7年了.早在2009年的时候GAE就在中国内 ...
- Android:真机调试遇到的问题(You need to use a Theme.AppCompat theme (or descendant) with this activity)
Android:真机调试遇到的问题(You need to use a Theme.AppCompat theme (or descendant) with this activity). 在调试&l ...
- CVPR 2019 | 用异构卷积训练深度CNN:提升效率而不损准确度
对于深度卷积神经网络而言,准确度和计算成本往往难以得兼,研究界也一直在探索通过模型压缩或设计新型高效架构来解决这一问题.印度理工学院坎普尔分校的一篇 CVPR 论文则给出了一个新的思路——使用异构的卷 ...
- 《Linux 性能及调优指南》1.6 了解Linux性能指标
翻译:飞哥 (http://hi.baidu.com/imlidapeng) 版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明. 原文名称:<Linux Performance a ...
- 聊聊 cursor鼠标样式
在前端开发中,很多时候需要对页面的某些元素做鼠标样式的处理,比如button一般用pointer , 文本区一般用text......等等. 今天咱就来聊聊 这个经常用到的 cursor 属性 cur ...
- Java file方法的路径特性
1.在flle方法里,直接写空白的路径,是会默认获取当前Java编译工作空间的路径. 例子如下: package example_1; import java.io.File; import java ...
- springBoot属性配置和使用
Spring Boot 属性配置和使用 1.添加属性文件 application.properties (名字固定) 2.访问端口生效 3.更多配置参考 # ===================== ...
- wgrib读grib数据
该文章来自博客:http://windforestwing.blog.163.c ... 412007103084743804/如有错误 ,大家及时指出啊!ps:meteoinfo可以直接处理grib ...