Programming Tutorials

Editing web.xml in a Struts Application

By: Gokul Verma in Struts Tutorials on 2007-04-04  

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.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Struts )

Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices

Configuring JDBC DataSources in Struts

Using Checkbox & Radio Tags, html:select, html:options in Struts Forms

ActionErrors and ActionError in Struts

Model 1 Architecture

Struts-GUI and Struts Console

Using JavaScript to submit a form in Struts

When is the best time to validate input in Struts

Using Multiple Message Resource Bundles in Struts

Writing the first Struts application

Use ImageButtonBean for Image based Form Submits in Struts

Use of {0} is required and Accessing resource bundles programmatically in Struts

What is Struts? Which Version of Struts to use?

Simple example of using the requiredif Validator rule in Struts

FAQ: Why was reload removed from Struts (since 1.1)?

Latest Articles (in Struts)