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 ...
随机推荐
- [POJ2625][UVA10288]Coupons
Description Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- git看不到别人创建的远程分支
解决办法: $ git fetch //取回所有分支(branch)的更新.如果只想取回特定分支的更新,可以指定分支名,例:$ git fetch <远程主机名> <分支名> ...
- 《Effective C#》读书笔记——条目13:正确地初始化静态成员变量<.NET资源管理>
我们知道在C#语言中创建一个类型的实例前,就应该初始化该类型的所有静态成员变量.C#语言为我们提供了静态初始化器和静态构造函数.其中,静态构造函数是一个特殊的构造函数,将在其他所有方法执行前以及变 ...
- Getting 'The AWS Access Key Id you provided does not exist in our records' error with Amazon MWS
I upgraded from one version of Amazon MWS (marketplace web service) version https://mws.amazonservic ...
- React中父子组件间的通信问题
1.https://blog.csdn.net/sinat_17775997/article/details/59103173 (React中父子组件间的通信问题)
- Android数据库升级不丢失数据解决方案
在Android开发中,sqlite至关重要,增删查改不多说,难点在于,1,并发,多个线程同时操作数据库.2,版本升级时,如果数据库表中新加了个字段,如何在不删除表的情况下顺利过渡,从而不丢失数据. ...
- 【Python】operator 模块简单介绍
简单介绍几个常用的函数,其他的请参考文档. operator.concat(a, b) **operator.__concat__(a, b)** 对于 a.b序列,返回 a + b(列表合并) -- ...
- 大于号转义符>---小于号转义符<
< < < 小于号 > > > 大于号 ≤ ≤ ≤ 小于等于号 ≥ ≥ ≥ 大于等于号 " " " 引号 “ “ 左双引号 ” ” ...
- 051——VUE中自定义指令:directive
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...