Struts2.0 configuration file (web.xml)

web.xml is the web application loads the important information about servlet configuration file, play initialization servlet, filter, etc. The role of web programs.
In general, all of the MVC framework for Web applications need to load a core controller, then what method to load the core of such a controller does, servlet or filter become a good choice, because they will with the opening of web services automatically loaded. For the Struts 2 framework, need to load FilterDispatcher, as long as the Web application is responsible for loading FilterDispatcher, FilterDispatcher will be loaded applications, Struts 2 framework.
Because Struts 2 will be the core controller designed to Filter, rather than a normal Servlet. Therefore, in order to allow Web application loading FilterDispacher, only need to configure the web.xml file can FilterDispatcher.
Configuration FilterDispatcher code snippet is as follows:

"! - Configure Struts 2 framework for the core of Filter ->
<filter>
"! - Struts 2 Core Filter to configure the name of -"
<filter-name> struts </ filter-name>
"! - Struts 2 Core Filter to configure the implementation class -"
<filter-class> org.apache.struts2.dispatcher.FilterDispatcher </ filter-class>
<init-param>
"! - Configure Struts 2 framework of the Action Pack structure is loaded by default -"
<param-name> actionPackages </ param-name>
<param-value> org.apache.struts2.showcase.person </ param-value>
</ init-param>
"! - Configure Struts 2 framework for the configuration of the provider class -"
<init-param>
<param-name> configProviders </ param-name>
<param-value> lee.MyConfigurationProvider </ param-value>
</ init-param>
</ filter>
"! - Configure Filter blocked URL ->
<filter-mapping>
"! - Configure Struts 2 core FilterDispatcher block all user requests -"
<filter-name> struts </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>
Three initialization parameters which have special meaning:
config: This parameter value is a comma (,) separated strings, each string is an XML configuration file. Struts 2 framework will automatically load the attribute specifies a series of configuration files.
actionPackages: The value of the parameter is also an English comma (,) separated strings, each string is a package of space, Struts 2 framework will scan the packages of space under the Action class.
configProviders: If you need to achieve their own ConfigurationProvider class, the user can provide one or more implements ConfigurationProvider interface class, and then these classes the class name set to the value of the property, a number of class names in English between the comma (, ) separated.
In addition, also here to configure Struts 2 constants, each <init-param> element to configure a Struts 2 constant, which <param-name> sub-element specifies the constant name, and the sub-elements <param-value> specified constant value.

As for the filter-mapping attribute filter (Filter) must be an attribute, used to filter the request path, where in general on the Set / * form of right to intercept all requests uri (filter), unless you have to do some special treatment.

At this point configuring struts2 core controller, and basically complete the struts2 configuration in the web.xml file.

Note that point: If the web container is J2EE1.3 (servlet2.3), due to not automatically load the struts tag library, so the need to manually load the web.xml file, struts tag library, the file name struts-tags.tld generally placed in WEB-INF Now, you can choose their own but if the web container is J2EE1.4 (servlet2.4), then the web container will automatically load the tag libraries, Struts 2 tag library definition file is included in the struts2-core-2.0 .6. jar file, in the struts2-core-2.0.6.jar file in META-INF path that contains a struts-tag.tld documents,
This file is the Struts 2 tag library definition file, Servlet 2.4 specification will automatically load the tag library file, which struts-tags.tld file contains loads of information pieces: is as follows:
<taglib>
"! - Custom tag library version of -"
<tlib-version> 2.2.3 </ tlib-version>
"! - JSP custom tag libraries required version of -"
<jsp-version> 1.2 </ jsp-version>
<short-name> s </ short-name>
"! - Definition of Struts 2 tag library URI, jsp file, the application uri ->
<uri> / struts-tags </ uri> ...
</ taglib>
The servlet2.3 manual configuration is as follows:
"! - Manually configure Struts 2 tag library -"
<taglib>
"! - Configure Struts 2 tag library URI jsp file, the application uri, similar to the name space -"
<taglib-uri> / s </ taglib-uri>
"! - Struts 2 tag library definition specifies the physical location of files -"
<taglib-location> / WEB-INF/struts-tags.tld </ taglib-location>
</ taglib>
Here is an example:

<? xml version = "1.0" encoding = "UTF-8"?>
<web-app 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> struts2 </ display-name>

<filter>
<filter-name> exportFilter </ filter-name>
<filter-class> org.displaytag.filter.ResponseOverrideFilter </ filter-class>
</ filter>

"! - Used to initialize the Spring container Listener ->
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ listener>

<filter>
<filter-name> struts2 </ filter-name>
<filter-class> org.apache.struts2.dispatcher.FilterDispatcher </ 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> 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>

</ web-app>

分类:Java 时间:2010-04-19 人气:1706
分享到:
blog comments powered by Disqus

相关文章

  • java application to read a complete sample configuration file 2008-12-01

    package com.jcms.cms.core; import java.io.BufferedInputStream; import java.io.InputStream; import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; / ** * * @ Author runningsnail * @ Date 2009-12-28 * * / public class Glo

  • Xiang Jie Struts configuration file, web.xml and struts-cofig.xml, as well as the struts-cofig.xml in the role of the various labels 2010-04-19

    Struts applications use two XML-based configuration files to configure, respectively web.xml and struts-cofig.xml file. Web.xml file is the configuration for all web applications, while the struts-config.xml file is struts-specific configuration file

  • Online Update web program implementation 2010-03-29

    To talk about the former realization of a web program's online update to give people who had not been achieved to provide a little thinking, this is my implementation of a project, perhaps not a good way, but it achieved the basic needs. The company

  • Apache and Nginx pseudo-static implementation 2010-04-23

    PHPWind pseudo-static rewrite rules 1, Apache pseudo-static (URL Rewrite) Set method: (1) Open the Apache httpd.conf configuration file (2) # LoadModule rewrite_module modules / mod_rewrite to remove the preceding # (3) In httpd.conf add: RewriteEngi

  • sruts2.0 web.xml configuration file 2011-05-04

    Any MVC framework and Web application integration needs, which had to resort to web.xml file, only the configuration in the web.xml file in the Servlet will be applied load. Usually, all the MVC framework for Web application needs to load a core cont

  • Platform for distributed applications based on Web Service basics Summary 2010-09-27

    One, Web Service's profile 1, What is Web Service Web services is to build interoperable distributed applications of the new platform. Web service platform is a standard that defines how applications to achieve interoperability in the Web. You can us

  • php apache configuration file 2010-10-15

    # # Based on NCSA server configuration files Prepared by the Rob McCool , Dragon Translation # # Apache The main server configuration file. Including the directory server settings instructions . # See # # Please understand the purpose of reading the

  • Detailed Apache configuration file httpd.conf 2011-03-29

    Detailed Apache configuration file httpd.conf # # Apache server is the main configuration file. Including the directory server command settings. # See <URL:http://www.apache.org/docs/> # # Please read to understand the basis of use of the command. #

  • web.xml configuration file Xiangjie 2010-04-19

    Deployment descriptor is actually an XML file that contains a lot of description of servlet / JSP applications in all aspects of the elements, such as the servlet registration , Servlet mapping as well as the listener registration. The deployment des

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.547 (s). 12 q(s)