Struts2 web.xml文件配置
在导入了项目需要使用的核心jar包之后需要在web.xml中配置Struts。
1. Struts2的知识点普及:
Struts2共有5类配置文件,分别罗列如下:
1), Web.xml;
在没有使用框架的时候,以前额JSP,Servlet程序中就配置过web.xml文件。准确地说web.xml不属于Struts2框架特有的配置文件。作为部署文件,web.xml是所有Java Web项目的核心文件。然而在这里之所以配置该文件。是因为在web项目中使用struts 2 框架时,还需要在web.xml中配置struts2的核心控制器(StrutsPrepareAndExecuteFilter),用于对struts2框架进行初始化和处理所有的请求。
具体配置文件如下:
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>StruteDemo</display-name>
<welcome-file-list>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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-app>
2), struts.properties;
3), struts.xml;
struts.xml定义应用自身使用的action映射及result,但我们一般将应用的各个模块分到不同的配置文件中。
首先,必须在struuts.xml文件的对应程序中做相应的配置,其中需要对每一个动作进行相应拦截器的调用,对每一种动作的运行结果进行配置等。在拦截器中,必须在使用前进行注册,struts配置文件可以支持继承,默认的配置文件包在Struts 2-core-x.x.x.jar中
<?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="false" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results>
<result name="error">/WEB-INF/jsp/error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings> <action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package> <include file="example.xml"/> <!-- Add packages here --> </struts>
4), struts-plugin.xml;
5), struts_default.xml;
Struts2 web.xml文件配置的更多相关文章
- Spring整合Hibernate的XML文件配置,以及web.xml文件配置
利用Spring整合Hibernate时的XML文件配置 applicationContext.xml <?xml version="1.0" encoding=" ...
- web.xml 文件配置01
web.xml 文件配置01 前言:一般的web工程中都会用到web.xml,方便开发web工程.web.xml主要用来配置Filter.Listener.Servlet等.但是要说明的是web. ...
- springmvc 项目完整示例07 设置配置整合springmvc springmvc所需jar包springmvc web.xml文件配置
前面主要是后台代码,spring以及mybatis的整合 下面主要是springmvc用来处理请求转发,展现层的处理 之前所有做到的,完成了后台,业务层和持久层的开发完成了 接下来就是展现层了 有很多 ...
- struts2 ,web.xml中配置为/*.action,运行报错Invalid <url-pattern> /*.action in filter mapp
首先,修改成: <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/ ...
- SSH项目搭建(五)——web.xml文件配置
上一章写到pom.xml有一个报错,说找不到web.xml文件.确实是这样的,因为我们用maven搭建的web层里就是没有这个文件.我们能看到,webapp文件夹里是空的. 没有,就想办法把它弄出来. ...
- SSH web.xml文件配置
启动一个WEB项目的时候, WEB容器会去读取它的配置文件web.xml web.xml中配置的加载优先级:context-param -> listener -> filter -> ...
- web.xml文件配置详解以及实例说明
1.web.xml学名叫部署描述符文件,是在Servlet规范中定义的,是web应用的配置文件. 2.部署描述符文件就像所有XML文件一样,必须以一个XML头开始.这个头声明可以使用的XML版本并给出 ...
- spring mvc学习笔记(一)web.xml文件配置的一点重要信息
通过这个web.xml文件可以看出,所有的*.shtml的请求,都会被springmvc这个servlet处理.这里如果没有指定contextConfigLocation这个参数,将会按照默认规则在c ...
- web.xml文件配置模板
直接贴完整代码,当然,spring的核心控制器依赖包需要通过mean提前配置 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.// ...
随机推荐
- 最小生成树------Kruskal算法
Kruskal最小生成树算法的概略描述:1 T=Φ:2 while(T的边少于n-1条) {3 从E中选取一条最小成本的边(v,w):4 从E中删去(v,w):5 if((v,w)在T中不生成环) { ...
- [记录]使用Gitblit 在windows 上安装Git Server
参考了: Windows平台下搭建Git服务器的图文教程 主要修改了:data/gitblit.properties # Include Gitblit's 'defaults.properties' ...
- scala学习笔记:理解函数
定义一个函数: scala> def foo(x:Int)=x*2 foo: (x: Int)Int 可以采用匿名参数: scala> def foo:((Int)=>Int) = ...
- ibatis 到 MyBatis区别
http://blog.csdn.net/techbirds_bao/article/details/9235309 简介: 本文主要讲述了 iBatis 2.x 和 MyBatis 3.0.x 的区 ...
- ASP的高效率的分页算法.net,php同样可以参考
一般习惯使用的有两种分页算法,一是传统的ADO分页,二是SELECT TOP分页算法.对于小型数据表,比如一两万的数据量的表,我倾向使用ADO算法,对于大型的数据表,则必须采用后者的算法了. 先来说说 ...
- C#集合之Hashtable
Hashtable是一个键值对集合,其泛型版本是Dictionary<K, V>,下面说下常用的一些方法; 1.Add(),向Hashtable添加元素,需要注意的是因为它是键值对集合,所 ...
- New Lantern Version Available Upgrade Lantern for improved blocking resistance!
New Lantern Version Available Upgrade Lantern for improved blocking resistance! The new version: is ...
- Java快速教程
作者:Vamei 出处:http://www.cnblogs.com/vamei Java是面向对象语言.这门语言其实相当年轻,于1995年才出现,由Sun公司出品.James Gosling ...
- 02线性表链式存储_LinkList--(线性表)
#include "stdio.h" #include "string.h" #include "ctype.h" #include &qu ...
- 【开发】Form Validate 表单验证 扩展应用
目录: ★.文本输入框(easyui-textbox) ★.数字框(easyui-numberbox) ★.时间(easyui-datebox) ★.文本域(easyui-textbox easyui ...