[struts]Write web.xml

  Because a Struts application is a Web application, it has to follow the same rules. that any Web application has to follow: Every Web application must have a web.xml configuration file. The web.xml file should define the ActionServlet,  which functions as a controller from the standpoint of the MVC(Model - View - Controller)framework. In other words, every request to a Struts application has to go through the ActionServlet. the ActionServlet is provided by the Struts frameword.

  The example web.xml file as shown below, has three different categories of configuration information:

  • ActionServlet configuraton
  • ActionServlet mapping
  • Struts tag library descriptors

  Under ActionServlet configuration section, note that several initialization parameters are specified as following through <init-param> elements:

  • <param-name>application</param-name>
    defines message resource file.  it is set as following:
        <init-param>
                <param-name>application</param-name>
                <param-value>ApplicationResources</param-value>
        </init-param>
  • <param-name>config</param-name>
    defines the path of the Struts configuration file. For example, the path of the Struts configuration file set to ./WEB-INF/struts-config.xml.
      <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/struts-config.xml<param-value>
      </init-param>

  Under ActionServlet mapping configuration section shown below, it is set in the way that every request that has *.do URL pattern will be handled by the ActionServlet.

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

  Under Struts tag Library Descriptors configurations section, note three Struts tag libraries are configured.

 A complete web.xml example:

 

<? xml version="1.0" encoding="ISO-8859-1" ?>

<! DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"
>

< web-app >
  
< display-name > Advanced J2EE Programming Class Sample App </ display-name >
  
  
<!--  Standard Action Servlet Configuration (with debugging)  -->
  
< servlet >
    
< servlet-name > action </ servlet-name >
    
< servlet-class >
      org.apache.struts.action.ActionServlet
    
</ servlet-class >
    
< init-param >
      
< param-name > application </ param-name >
      
< param-value > ApplicationResources </ param-value >
    
</ init-param >
    
< 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 > 2 </ param-value >
    
</ init-param >
    
< init-param >
      
< param-name > detail </ param-name >
      
< param-value > 2 </ param-value >
    
</ init-param >
    
< init-param >
      
< param-name > validate </ param-name >
      
< param-value > true </ param-value >
    
</ init-param >
    
< load-on-startup > 2 </ load-on-startup >
  
</ servlet >

 
  
<!--  Standard Action Servlet Mapping  -->
  
< servlet-mapping >
    
< servlet-name > action </ servlet-name >
    
< url-pattern > *.do </ url-pattern >
  
</ servlet-mapping >

 
  
<!--  Struts Tag Library Descriptors  -->
  
< taglib >
    
< taglib-uri > /WEB-INF/struts-bean.tld </ taglib-uri >
    
< taglib-location > /WEB-INF/struts-bean.tld </ taglib-location >
  
</ taglib >

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

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

</ web-app >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值