Editing web.xml in a Struts Application

By: Gokul Verma  

The web.xml file is where servlets and other stuff are defined to the servlet container. We'll remove some unnecessary things from the web.xml file so it looks like this:

<?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>

  <!-- 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>

The web.xml file -

The file contains three sections:

  1. the definition of the Struts servlet named "ActionServlet"
  2. the URL mapping for the calls to this servlet
  3. the definitions of the Struts tag libraries

You'll see that the servlet will be called if our browser requests a file called <some-name>.do. So when we submit the form in our one-page application we'll decide to use the action-name "submit.do". How the Struts servlet knows what to do with this request we'll discover next.




Archived Comments

1. need to be place taglig in the <jsp-config> tag without this will be a error
View Tutorial          By: Shaik Basha at 2013-01-30 03:11:41

2. what is the usage of 'detail' and 'debug' init parameters in web.xml.
View Tutorial          By: uday at 2011-07-21 04:53:02

3. good
View Tutorial          By: rajesh sharma at 2011-07-18 05:20:56

4. where should i define some property so as my site calls an action when loading, and not a view direc
View Tutorial          By: juan villegas at 2010-06-12 01:24:43

5. yes simple good it wroking goog
View Tutorial          By: durga prasad pavirala at 2009-02-11 03:43:04


Most Viewed Articles (in Struts )

Latest Articles (in Struts)

Comment on this tutorial