一、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的更多相关文章

  1. Struts2学习一----------Struts2的工作原理及HelloWorld简单实现

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2工作原理 一个请求在Struts2框架中的处理步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2.这个请求 ...

  2. struts2学习(2)struts2核心知识

    一.Struts2 get/set 自动获取/设置数据 根据上一章.中的源码继续. HelloWorldAction.java中private String name,自动获取/设置name: pac ...

  3. Struts2学习笔记--Struts2的体系结构

    1. Struts2体系结构 Struts是以前端控制器框架为主体的框架,用户的请求会通过控制器选择不同的Action类来执行具体的操作,在Action类中所有的Servlet对象(request.r ...

  4. Struts2学习笔记——Struts2与Spring整合

      Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...

  5. struts2学习(15)struts2防重复提交

    一.重复提交的例子: 模拟一种情况,存在延时啊,系统比较繁忙啊啥的. 模拟延迟5s钟,用户点了一次提交,又点了一次提交,例子中模拟这种情况: 这样会造成重复提交:   com.cy.action.St ...

  6. struts2学习(14)struts2文件上传和下载(4)多个文件上传和下载

    四.多个文件上传: 五.struts2文件下载: 多个文件上传action com.cy.action.FilesUploadAction.java: package com.cy.action; i ...

  7. struts2学习(13)struts2文件上传和下载(1)

    一.Struts2文件上传: 二.配置文件的大小以及允许上传的文件类型: 三.大文件上传: 如果不配置上传文件的大小,struts2默认允许上传文件最大为2M: 2097152Byte:   例子实现 ...

  8. struts2学习(12)struts2验证框架2.自定义验证

    一.例子需求: 对敏感词进行验证: 将struts包中的validators.xml文件拷贝一份到src目录下,在最后面添加自己的验证器: com.cy.validators.SensitiveWor ...

  9. struts2学习(11)struts2验证框架1.验证简介、内置验证

    一.Struts2验证简介: 二.struts2内置验证: 下面例子,需求是:为用户注册进行验证: com.cy.model.User.java: package com.cy.model; publ ...

随机推荐

  1. Python学习札记(二十六) 函数式编程7 修饰器

    修饰器 NOTE 1.函数对象有一个__name__属性,可以拿到函数的名字: #!/usr/bin/env python3 def now(): print('2017/2/19') def mai ...

  2. [原][osgearth]设置OE的高程,高度场的数据。修改设置高度值

    ; row < hf->getNumRows(); ++row ) { ; col < hf->getNumColumns(); ++col ) { float val = h ...

  3. Java网络编程和NIO详解9:基于NIO的网络编程框架Netty

    Java网络编程和NIO详解9:基于NIO的网络编程框架Netty 转自https://sylvanassun.github.io/2017/11/30/2017-11-30-netty_introd ...

  4. SVN 提交代码时强制加入注释内容

    参考: 关于SVN提交强制加入注释 方式一是使用的服务器脚本,对所有SVN用户生效. 方式二是使用本地钩子,仅对当前SVN用户生效.

  5. MySQL多表关联查询与存储过程

    --  **************关联查询(多表查询)**************** -- 需求:查询员工及其所在部门(显示员工姓名,部门名称) -- 1.1 交叉连接查询(不推荐.产生笛卡尔乘积 ...

  6. Loops with PL/SQL

    1. Basic loop loop /* statements */ end loop; 2. While loop while a > b loop /* statements */ end ...

  7. iOS 地图 通过经纬度计算两点间距离

    - (double)calculateStart:(CLLocationCoordinate2D)start end:(CLLocationCoordinate2D)end { ; double st ...

  8. linux下之mysql篇

    网上查到的一般是 yum install mysql yum install mysql-server yum intall mysql-devel 但是在centos7下  mysql-server ...

  9. ps cs6破解

    http://www.cnit618.com/html/rjxz/yyrj/3011.htm 这个破解方法太简单.注:文中最后给出补丁.我用了方法二破解:代替amtlib.dll.一下子就可以.

  10. python将字符转换为字典

    参考文章Python 如何将字符串转为字典 注意: 使用json的时候一定要注意是loads而不是load 即:user_dict = json.loads(user_info) 注意: 用eval( ...