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 ...
随机推荐
- [RxJS] Create a Reusable Operator from Scratch in RxJS
With knowledge of extending Subscriber and using source.lift to connect a source to a subscriber, yo ...
- org.json.JSONException: A JSONObject text must begin with '{' at character 1 of {解决方法
在使用java读取一个本地的json配置文件的时候,产生了这个异常:org.json.JSONException: A JSONObject text must begin with '{' at c ...
- yii2利用自带UploadedFile上传图片
创建一个 models/UploadForm.php: <?php namespace app\models; use yii\base\Model; use yii\web\UploadedF ...
- centos 安装tkdiff
http://sourceforge.net/projects/tkdiff/files/tkdiff/4.2/ 下载tkdiff-4.2.tar.gz 然后在centos下解压 将tkdiff c ...
- oracle官方文档_查看初始化參数(举例)
原创作品,出自 "深蓝的blog" 博客.深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46864217 记录 ...
- 使用JS对select标签进行联动选择
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- Sql数据库查询语言
1.概述 Sql是一种面向数据库的结构化查询语言.是符合美国国家标准化组织ANSI的一种计算机标准语言. Sql具对数据库的操作有:增删改查.创建数据库.创建表.创建存储过程.创建视图等 RDBMS关 ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) D.Dinner Bet 概率DP+排列组合
题目链接:点这里 题意: 1~N标号的球 现在A有C个,B有C个 每次可以随机得到D个不同的球(1~N);问你A或B中的C个球都出现一次的 期望次数 题解: dp[i][j][k]表示 随机出现了i个 ...
- Linq:int类型使用Contains方法
获取的是前台传过来的String类型的值,例如:1,123,44,59 具体代码如下 if (!string.IsNullOrEmpty(str)) { string[] strArr = str.S ...
- debian repository的成长过程
1 基本概念 1.1 健康的安装 在端系统中的一次健康的安装指的是,在安装的包的集合中,所有的依赖都满足,并且没有冲突存在. 这的健康的安装是相对于端系统而言的,并不是相对于整个repo而言的.对整个 ...