Now that we have configured our project for struts,let’s have a look at the configurations MyEclipse has made for us.
Web.xml Web.xml resides in application’s WEB-INF directory and contains the essential configuration for the web application like the Servlet mappings,Authentications mechanisms,Tag libraries etc. Let’s see what is in web.xml right now.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" axmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee qqhttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <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> </web-app>
As we can see,there is one Servlet configured and is mapped with URL pattern *.do. What is this ‘ActionServlet’ for? This is the simple way how the Struts CONTROLER is plugged into the web application.
The basic reason of defining a servlet mapping for a web application is that whenever someone access a page that matches the URL pattern defined in servlet mapping,Application Server will redirect the request to this servlet. That means,we have configure Struts Action Servlet to receive all the request that end with a .do keyword. We can even configure it for .html or .jsp or .abc,.do is the generally accepted token.
Struts-config.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources /> <form-beans /> <global-exceptions /> <global-forwards /> <action-mappings /> <message-resources parameter="com.visualbuilder.struts.ApplicationResources" /> </struts-config>
We don’t have anything special in this file configured,but as you can see,we have the basic tags. We’ll add the appropriate struts components to these tags as we develop them. One important thing in this file is the message-resources. This is a resource bundle that will contain all the errors,labels or other messages that we want to display on the view (jsp pages). The separation of the String messages from the jsp pages helps internationalization.
|