Struts2.0 configuration file (web.xml)

sponsored links
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 ->
"! - 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>
"! - 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 -"
<param-name> configProviders </ param-name>
<param-value> lee.MyConfigurationProvider </ param-value>
</ init-param>
</ filter>
"! - Configure Filter blocked URL ->
"! - 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:
"! - 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 -"
"! - 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 = "" xmlns: xsi = "" xsi : schemaLocation = "">
<display-name> struts2 </ display-name>

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

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

<filter-name> struts2 </ filter-name>
<filter-class> org.apache.struts2.dispatcher.FilterDispatcher </ filter-class>
</ filter>

<filter-name> struts2 </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>

<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>
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Struts2.0 configuration file (web.xml)

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @

  • Learn Java flow

    Related Articles: J2EE without EJB Introducing to Spring Framework (English revised edition) J2EE without EJB caused consider Recommend circles: reading space More related recommend Java Learning Path (1), tools, articles First, JDK (Java Development Kit)

  • hibernate generic generic DAO

    package org.lzpeng.dao; import; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

  • spring struts2.0 hibernate bug killer 1

    exception There is no Action mapped for namespace / and action name checkLogin. - [Unknown location] com.opensymphony.xwork2.DefaultActionProxy.prepare ( 186) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries