2016/10/29 Action类中execute方法的使用
第一步:先配置web.xml文件
<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.xml
第二步:创建相关Action.java文件
package com.Test.action;
public class HelloAction {
String info;
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String execute() {
setInfo("execute執行成功!!!");
System.out.println("执行..............");
return "success";
}
}
HelloAction.java
第三步:创建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="true" />
<package name="helloPackage" extends="struts-default">
<action name="helloAction" class="com.Test.action.HelloAction" method="execute">
<result name="success">/hello.jsp</result>
</action>
</package>
</struts>
struts.xml
第四步:创建index.jsp文件
<%@ 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>
<h1>JAVA HELLO WORLD!!!</h1>
<h3>class="com.Test.action.HelloAction"</h3>
<h4><!-- 动态方法调用 -->constant name="struts.enable.DynamicMethodInvocation" value="true" </h4>
<!--
宅课学院用法,不起作用
<a href="../helloAction/hello.jsp">..............</a>
-->
<a href="helloAction!execute">添加</a>
</body>
</html>
index.jsp
第五步:创建struts.xml中对应的jsp文件
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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>
<h1>Hello.jsp</h1>
<s:property value="'helloWorld'"/>
<s:property value="info"/>
</body>
</html>
hello.jsp
注意:1、在配置struts.xml中,写action中最好要加一个method方法,action下面的result是该method方法返回的值,通过此值找到对应的jsp页面
2、写东西时思维不能固话,不能视频上怎么写我就怎么写,不然永远都找不到问题,要按照自己所熟悉的方法去做!!!
2016/10/29 Action类中execute方法的使用的更多相关文章
- 第五课 Struts的控制器【续】Action类的execute()方法
1.Action类的execute()方法: public ActionForward execute(ActionMapping mapping, ...
- 2016/10/29 action与form表单的结合使用
1>web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi= ...
- 转载 Struts2之------Action类中的get,set方法和execute方法的使用规范和使用流程(规范是没有理由的,必须遵守!!!)
1,Action中get,set方法的使用流程? 前台form中有一个<input type="text" name="username"/> 如果 ...
- 在Action类中获得HttpServletResponse对象的四种方法
在struts1.xAction类的execute方法中,有四个参数,其中两个就是response和request.而在Struts2中,并没有任何参数,因此,就不能简单地从execute方法获得Ht ...
- Action类中获取request等对象的方法
struts2中的action类中,SevletActionContext可以获取
- action类中属性驱动和模型驱动的区别
1.Struts2的属性驱动 在Action类中,属性××通过get××()和set××()方法,把参数在整个生命周期内进行传递,这就是属性驱动 代码如下: package org.abu.csdn. ...
- 2016.10.29初中部上午NOIP普及组比赛总结
2016.10.29[初中部 NOIP普及组 ]模拟赛 做得好爽! 进度: 比赛:35+45+AC+0=180 改题:AC+AC+AC+0=300 幸运的数 有点无语--之前怕超限,还特意利用程序打了 ...
- 在jsp中选中checkbox后 将该记录的多个数据获取,然后传到Action类中进行后台处理 双主键情况下 *.hbm.xml中的写法
在jsp中选中checkbox后 将该记录的多个数据获取,然后传到Action类中进行后台处理 双主键情况下 *.hbm.xml中的写法 ==========方法1: --------1. 选相应 ...
- swift -- 类中的方法
一. 引用类型 类 在类中定义方法 class Person { //属性 var name : String = "" //方法 //实例方法 : 在类里面创建一个方法 fun ...
随机推荐
- poj 1426 Find The Multiple ( BFS+同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18390 Accepted: 744 ...
- MongoDB使用入门
1.MongoDB的安装 步骤一:下载MongoDB 下载安装包:http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz 步骤二:设置 ...
- Atitit. 软件GUIbutton与仪表盘--webserver区--获取apache配置文件路径 linux and apache的启动、停止、重新启动
Atitit. 软件GUIbutton与仪表盘--webserver区--获取apache配置文件路径 linux and apache的启动.停止.重新启动 能够通过"netstat ...
- 遍历数据库全部表,将是datetime类型的列的值进行更新
declare @tablename nvarchar(80) declare @cloumn nvarchar(80) declare @sql nvarchar(400) declare ...
- Sublime Text 3.3143最新注册码
Sublime Text3之前用的是老版本,昨天手贱点了更新,就要重新激活,网上找了好多都是之前版本的,以下给干货 —– BEGIN LICENSE —– TwitterInc User Licens ...
- mt7620 uboot
我本机装的是64位Ubuntu, SDK 里提供的 buildroot-gcc342 是32位的,无法直接运行,需要先安装 gcc-multilib. sudo apt-get install gcc ...
- 基于开源项目的在线网络视频直播项目---pc端的推流
https://github.com/winlinvip/simple-rtmp-server/issues/66 https://github.com/justinmakaila/iOS-Frame ...
- Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现
pager-taglib分页開始~ 查了好多关于分页的技术,终于选定下面方法实现~ 1.首先下载jar包:pager-taglib.jar,pager-taglib.jar放在WEB-INF/lib文 ...
- [IT学习]从网上获取pdf制作vce文件
考过IT证书的朋友,都知道什么是vce文件.如果仅仅找到了pdf版本的文件,该如何转为vce文件呢? 具体的步骤如下: 1.到如下网址下载examformatter,http://www.examco ...
- USACO45 lights 电灯(折半搜索)
刚刚上一篇博客才D了队长一发,心里虚的慌......万分感谢队长给讲折半搜索!!听说这题可以高斯消元(可是我不会...貌似折半我也不会) 这题呢,一想到就是爆搜啦,然而,爆搜2^35必跪,折半搜索,就 ...