002-web.xml Configuring additional Frameworks

Source: Internet
Author: User
Tags tld

1. Configure Spring 1.1. Steps

1. Load the configuration file.
2, set the starting mode.

1.2. Load the configuration file

Load a single file under Web-inf:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

Load multiple files under web-inf/classes:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:* */applicationcontext*.xml</param-value>
</context-param>

Where "**/applicationcontext*.xml" represents an XML configuration file that begins with "ApplicationContext" in any directory.
It is not recommended to use any path, it is recommended to use Applicationcontext*.xml
If multiple files are loaded, separate them with commas.

1.3. Set the startup mode

There are three ways to start spring:
Contextloaderlistener (recommended)
Contextloaderservlet (not supported on spring3.0 version)
Contextloaderplugin (not supported on string2.0 version)

1.3.1.ContextLoaderListener

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

1.3.2.ContextLoaderServlet

<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

This method is intended to be used for web containers that do not support listening.

1.3.3.ContextLoaderPlugIn

<plug-in classname= "Org.springframework.web.struts.ContextLoaderPlugIn" >
<set-property property= "contextconfiglocation" value= "/web-inf/applicationcontext.xml"/>
</plug-in>

This method requires import: Org.springframework.web.struts-3.0.5.release.jar
This package is not supported after struts2.0.

2. Configuring STRUTS1 2.1. Steps

1, configuration Actionservlet.
2. Configure Struts Tag library?
3. Configure the list of welcome documents.
4, configuration error handling.

2.2. Configure Actionservlet

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

1. No matter how many sub-applications are included in the app, you only need to configure one actionservlet because Actionservlet supports multithreading, and the current struts framework allows only one actionservlet to be configured in the app.

2. <init-param>
<param-name>config</param-name>
<param-value>WEB-INF/struts-config.xml</param-value>
</init-param>

Here is a relative path to indicate the configuration file location of the struts application. If not set, the default value is/web-inf/struts-config.xml.
When multiple people collaborate on a project, the STRUTST configuration file can be expanded appropriately, but it must start with CONFIG. Such as:
<init-param>
<param-name>config/XXXXXXXXX</param-name>
<param-value>/WEB-INF/XXXXX.xml</param-value>
</init-param>

To configure multiple files, the value of param-name must begin with CONFIG.
The root URL immediately follows xxxxxxxxx access to the current configuration.

3. <init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>

Set the debug level of the servlet to control the verbosity of the logging. The default is 0, which records relatively minimal log information.
4. <init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
Setting the debug level of the Digester, Digester is a framework used by the struts framework to parse the XML configuration file, which allows you to view the parsing logs for different levels of detail. The default is 0, which records relatively minimal log information.

5. <servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

is to submit all the *.do requests to the action, and from here to the above configuration can be read to the location of Actionservlet.

6. <load-on-startup>0</load-on-startup>

Actionservlet the order that is loaded when the server is opened, the lower the value, the more loaded.

2.3. Configuring the Struts Tag Library

<taglib>
<tag-uri>/WEB-INF/struts-html.tld<tag-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

Tag-uri: Used to specify a relative or absolute URI address for a tag library, the Web app accesses the tag library based on that URI.
Taglib-location: Specifies the physical location of the label description file in the file resource system.

2.4. Configure a list of welcome files

When a customer accesses a web app, what if only the root of the Web app is given? URL, no specific file name specified. The Web container automatically calls the Web app's welcome file. <welcome-file-list> is used to set this item.
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>

Description: You can have multiple <welcom-file> under <welcome-file-list>. The Web container will look for the Welcome screen in turn until it is found. However, if it does not exist, an "HTTP 404 Not Found" error message is returned to the client.
Because servlet mappings cannot be configured in the <welcome-file-list> element, the struts action cannot be directly used as a welcome file.

A:welcome.jsp page (can change file name)
<script language= "javascript" >location.href= "Xxxx.do" </script>

B:web.xml
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>

C, struts1 configuration xxxx.do

2.5. Configuring error handling

All errors or exceptions cannot be handled in the struts framework. When the struts framework fails to handle all errors or exceptions, it throws the error to the Web container. By default, the Web container returns the original error directly to the user's browser.

3. Configuring STRUTS2 3.1. Steps

1. Configure Filter.
2. Configure the list of welcome documents.
3, configuration error handling.

3.2. Configure the filter

<filter>
<filter-name>strutsfilter</filter-name>
<filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class>
</filter>

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

Configuration content also has the <init-param> settings filter initialization parameters. There is no specific explanation, because these can also be defined within the Struts.properties file.

3.3. Configure the list of welcome files.

With Struts1

3.4. Configure error handling.

With Struts1

4. Configure log4j

Spring dynamically changes the log4j record level and policy without restarting project modifications.

4.1. Steps

1. Configure the project publishing path.
2. Configure the configuration file path.
3, configure the scan file time.
4, configuration monitoring.

4.2. Configure the Project publishing path

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>

Project release path, the same middleware container the Param-value value of this configuration cannot be the same. The default configuration is: Webapp.root
Java is available through System.getproperty ("Webapp.root").
Log4j.propertis can be ${webapp.root} value (if Middleware is Tomcat): Tomcat installation directory/tomcat/webapps/project name

4.3. Configure the profile path

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>

Class Path:<param-value>classpath:log4j.properties</param-value>

4.4. Configure scan file time (in milliseconds)

<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>

4.5. Configuring monitoring

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

5. Configure DWR

002-web.xml Configuring additional Frameworks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.