struts2中struts.xml和web.xml文件解析及工作原理
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://Java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Struts Blank</display-name> <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> <welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> </web-app>
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> <!-- consant 常量,struts.devMode表示开发者模式,当为true时如果改变了其中的一些代码,可以不用重新启动tomcat-->
<constant name="struts.devMode" value="true" /> <!--package可以有多个解决重名的情况, namespace 可以不写,默认是如何路径都可以,也可以写成/xx/yy ,必须是/开头-->
<package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results>
<result name="error">/error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings> <!-- action里面那个name属性值得是URL输入的路径名 ,如“http://localhost:8080/Struts2Demo/hello”,则会根据result反馈Hello.jsp-->
<action name="hello" class="com.styspace.struts2.action.action2">
<result> /Hello.jsp</result>
</action> <!-- action里面class属性值,会有对应的这个类,执行该类里面的execute()方法--> <action name="action" class="com.styspace.struts2.action.action2">
<result name="success">/Action.jsp</result>
</action> <!-- action里面method属性值,会有对应class这个类中的add方法,然后执行该方法--> <action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add">
<result>/user_add_success.jsp</result>
</action> <!-- 一般action里面不用method属性值,而是用DMI(动态方法调用)可以通过http://localhost:8080/Struts2Demo/user!addURL调用,其中user指的是action中的name值--> <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
<result>/user_add_success.jsp</result>
</action> <!-- 更简单的方法,通配符,name=“student*”会匹配URL中所有Studentxx,而method=“{1}”指的是name中第一个“*”匹配的值 同理,result中{1}也是一样的--> <action name="Student*" class="com.bjsxt.struts2.action.StudentAction" method="{1}"> <result>/Student{1}_success.jsp</result>
</action>
<!-- 甚至可以有多个通配符,class属性中也可以用{1}来匹配,最简化-->
<action name="*_*" class="com.bjsxt.struts2.action.{1}Action" method="{2}">
<result>/{1}_{2}_success.jsp</result>
<!-- {0}_success.jsp -->
</action> </package>
<!-- Add packages here --> </struts>
工作原理:
struts2中struts.xml和web.xml文件解析及工作原理的更多相关文章
- struts2中struts.xml 放置路径的问题
在搭建struts2项目时如果在web.xml中不指定struts.xml文件的路径,struts2会默认到/WEB-INF/classes中寻找加载其配置文件的,但我就是想把struts的配置文件放 ...
- 关于TOMCAT中的两个Web.xml
关于TOMCAT中的两个Web.xml (2013-01-19 17:32:57) 转载▼ 标签: 杂谈 初学JAVA web开发.. Servlet定义的时候,我发现在${catalina.ho ...
- Eclispe创建maven工程缺失web.xml报web.xml is missing and <failOnMissingWebXml> is set to true的错误
Eclispe创建maven工程缺失web.xml报web.xml is missing and <failOnMissingWebXml> is set to true的错误,一看,还缺 ...
- 游戏开发中IIS常见支持MIME类型文件解析
游戏开发中IIS常见支持MIME类型文件解析 .apkapplication/vnd.android .ipaapplication/vnd.iphone .csbapplication/octet- ...
- Atitit。Tree文件解析器的原理流程与设计实现 java c# php js
Atitit.Tree文件解析器的原理流程与设计实现 java c# php js 1. 解析原理与流程1 1.1. 判断目录 ,表示服 dirFlagChar = "└├─&quo ...
- JAVA之旅(二十五)——文件复制,字符流的缓冲区,BufferedWriter,BufferedReader,通过缓冲区复制文件,readLine工作原理,自定义readLine
JAVA之旅(二十五)--文件复制,字符流的缓冲区,BufferedWriter,BufferedReader,通过缓冲区复制文件,readLine工作原理,自定义readLine 我们继续IO上个篇 ...
- 一图看懂hadoop分布式文件存储系统HDFS工作原理
一图看懂hadoop分布式文件存储系统HDFS工作原理
- struts2中struts.xml配置文件详解【未整理】
1. 深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1. 包配置: Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管 ...
- Struts2配置文件复用代码【web.xml、struts.xml、常量配置】
web.xml的分发器代码: <!-- 引入struts核心过滤器 --> <filter> <filter-name>struts2</filter-nam ...
随机推荐
- C++第15周(春)项目2 - 用文件保存的学生名单
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759.内有完整教学方案及资源链接 本程序中须要的相关文件.请到http://pa ...
- map以自定义类型当Key
关于map的定义: template < class Key, class T, class Compare = less<Key>, class Allocator = alloc ...
- mysql 5.7安装教程
一.mysql下载地址 https://downloads.mysql.com/archives/installer/ 说在前面的话 我为什么已经尝试和使用过同类型产品的很多MySQL版本,还要书写 ...
- 常用IP核
前言 记录自己用到的模块,随时补充. 主要分类: 一.常用模块 1-FIFO FIFO分为两种,一是输入输出时钟相同(Common clock)的 fifo ;二是输入输出时钟不相同(Independ ...
- Redis 实现队列优先级
通常使用一个list来实现队列操作,这样有一个小限制,所以的任务统一都是先进先出,如果想优先处理某个任务就不太好处理了,这就需要让队列有优先级的概念,我们就可以优先处理高级别的任务. 实现方式: (1 ...
- vim设置文本宽度
'textwidth' 'tw' number (default 0) local to buffer ...
- UrlOper
using System; using System.Text.RegularExpressions; using System.Web; using System.Collections.Speci ...
- 简单好用的hash表-----uthash
在软件开发中,不可不免的会使用到hash表,hash表的优点这里就不说了,以下介绍一个hash表的C实现, uthash是用宏实现的,使用的时候非常方便,只用包含uthash.h即可. Uthash的 ...
- posix多线程--三种基本线程编程模型
本文介绍了三种构建线程解决方案的方式. 一.流水线:每个线程执行同一种操作,并把操作结果传递给下一步骤的线程. 代码示例如下:终端输入一个int值,每个线程将该值加1,并将结果传给下一个线程. #in ...
- 在eclipse中执行sql
只要你配置好了你的database(在Data Source Explorer中,可以通过window->show view打开) 写好你的sql script,然后配置好profile 右键, ...