struts2学习(1)struts2 helloWorld
一、struts2简介:

二、helloWorld:
1)工程结构:

HelloWorldAction.java:
package com.cy.action;
import com.opensymphony.xwork2.Action;
public class HelloWorldAction implements Action{
public String execute() throws Exception {
System.out.println("执行了Action的默认方法");
return SUCCESS;
}
}
struts.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> <!-- 可以创建很多的package,用name来区分 -->
<package name="helloWorld" extends="struts-default">
<action name="hello" class="com.cy.action.HelloWorldAction">
<!-- 默认是转发,转发到helloWorld.jsp -->
<result name="success">helloWorld.jsp</result>
</action>
</package> </struts>
web.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Struts2Chap01</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> <filter>
<filter-name>Struts2</filter-name>
<!-- struts2的核心控制器 -->
<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>
helloWorld.jsp:
<body>
struts2你好!!
</body>
2)测试结果:
浏览器中访问:http://localhost:8080/Struts2Chap01/hello

struts2学习(1)struts2 helloWorld的更多相关文章
- Struts2学习一----------Struts2的工作原理及HelloWorld简单实现
© 版权声明:本文为博主原创文章,转载请注明出处 Struts2工作原理 一个请求在Struts2框架中的处理步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2.这个请求 ...
- struts2学习(2)struts2核心知识
一.Struts2 get/set 自动获取/设置数据 根据上一章.中的源码继续. HelloWorldAction.java中private String name,自动获取/设置name: pac ...
- Struts2学习笔记--Struts2的体系结构
1. Struts2体系结构 Struts是以前端控制器框架为主体的框架,用户的请求会通过控制器选择不同的Action类来执行具体的操作,在Action类中所有的Servlet对象(request.r ...
- Struts2学习笔记——Struts2与Spring整合
Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...
- struts2学习(15)struts2防重复提交
一.重复提交的例子: 模拟一种情况,存在延时啊,系统比较繁忙啊啥的. 模拟延迟5s钟,用户点了一次提交,又点了一次提交,例子中模拟这种情况: 这样会造成重复提交: com.cy.action.St ...
- struts2学习(14)struts2文件上传和下载(4)多个文件上传和下载
四.多个文件上传: 五.struts2文件下载: 多个文件上传action com.cy.action.FilesUploadAction.java: package com.cy.action; i ...
- struts2学习(13)struts2文件上传和下载(1)
一.Struts2文件上传: 二.配置文件的大小以及允许上传的文件类型: 三.大文件上传: 如果不配置上传文件的大小,struts2默认允许上传文件最大为2M: 2097152Byte: 例子实现 ...
- struts2学习(12)struts2验证框架2.自定义验证
一.例子需求: 对敏感词进行验证: 将struts包中的validators.xml文件拷贝一份到src目录下,在最后面添加自己的验证器: com.cy.validators.SensitiveWor ...
- struts2学习(11)struts2验证框架1.验证简介、内置验证
一.Struts2验证简介: 二.struts2内置验证: 下面例子,需求是:为用户注册进行验证: com.cy.model.User.java: package com.cy.model; publ ...
随机推荐
- 谷歌浏览器&360浏览器安装——有道云笔记插件
谷歌浏览器: 有道云笔记插件:http://hk.chromefor.com/down.php?key=FulQTdJ9In3iXfdVicFW(点击即下载) 在谷歌浏览器里按快捷键:Alt+E 接 ...
- Windows 搭建 Linux kernal0.11 环境
下载:http://www.oldlinux.org/Linux.old/bochs/ 安装bochs 运行 界面:
- ResourceNotFound: rosbridge_server
Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking ...
- [OSG]OSG的相关扩展
参考:osg官网 http://www.osgchina.org/index.php?view=article&id=176 http://trac.openscenegraph.org/pr ...
- 树状数组 Binary Indexed Tree/Fenwick Tree
2018-03-25 17:29:29 树状数组是一个比较小众的数据结构,主要应用领域是快速的对mutable array进行区间求和. 对于一般的一维情况下的区间和问题,一般有以下两种解法: 1)D ...
- java裁剪图片
java裁剪图片保存到指定位置 /** * 图片裁剪通用接口 * * @param src 源图片地址,图片格式PNG * @param dest 目的图片地址 * @param x 图片起始点x坐标 ...
- Git观察和比较
log git log 时间是从下到上,从远到近 whatchanged git whatchanged 时间是从下到上,从远到近 diff --staged 比较工作区和缓存区之间的差异 g ...
- 获得文件路径 _pgmptr, _makepath, _splitpath
#include <stdlib.h> #include <stdio.h> int main(void) { char path_buffer[_MAX_PATH]; cha ...
- vue.js-列表分页
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- BootStrap--scroll
滚动侦测 滚动侦测基本使用方法为: <body data-spy="scroll"> <nav class="navbar navbar-default ...