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 ...
随机推荐
- @Retention n. 保留
@Retention n. 保留 学习了:https://blog.csdn.net/asdgbc/article/details/70196749 默认都是保留到class中,而在runtime中没 ...
- 分享一个纯css制作的动画化,在网页(手机)载入等的时候能够引用!
CSS代码例如以下: /* Custom Stylesheet */ body, html { margin: 0; -webkit-font-smoothing: antialiased; back ...
- JavaSE入门学习9:Java基础语法之数组
一数组的定义 数组能够理解为是一个巨大的"盒子",里面能够按顺序存放多个类型同样的数据.比方能够定义int型的数组 scores存储4名学生的成绩. watermark/2/tex ...
- Android中个人推崇的数据库使用方式
手机应用开发中常常会使用到数据库存储一些资料或者进行数据缓存,android中为我们提供了一个轻量的数据库.在上层进行了一层封装,同一时候还为我们提供了ContentProvider的框架.方便我们进 ...
- 将Python打印的内容进行高亮的输出
将打印的内容进行高亮的显示 内容: 格式: echo "\033[字背景颜色;字体颜色m字符串\033[0m" 例如: "\033[41;36m something he ...
- notepad++ 查找引用(Find Reference)(适用于c c++及各类脚本比方lua、python等)
在程序开发过程中,程序猿经经常使用到的一个功能就是查找引用(Find Reference).Visual Studio里面的相应功能是"查找全部引用"(Find All Refer ...
- Linux Chromium安装Adobe Flash Player
首先,下载: install_flash_player_11_linux.i386.tar.gz 解压文件: tar -xvf install_flash_player_11_linux.i386.t ...
- 配置 Apache 服务器禁止所有非法域名 访问自己的服务器
.http2..1以前: 第一种 直接拒绝访问 打开 httpd.conf 文件,将一下配置追加到文件最后. <pre name="code" class="htm ...
- Datagrid接收JSON数据格式
开打View下面的Shared创建一个视图模版(母版页)<!DOCTYPE html> <html> <head> <title>Main</ti ...
- 修改系统时间(取得服务器时间,使用SetLocalTime API函数,需要UAC权限)
我的客户遇到系统时间不对,自己又不会改,于是想到利用服务端时间来修改本地的系统时间. 第一步,把下面xml存成uac.xml文件备用. <?xml version="1.0" ...