Configure struts-config.xml into web.xml

Configure struts-config.xml into web.xml

Previous Home Next

 

The main xml file of an web based application is web.xml file.when request come from client then first web.xml is call by server .On the behalf of configurations into web.xml the server performs some task and lastly give response to client. For struts based application struts-config.xml and web.xml are required .We must have configure struts-config.xml into web.xml so that when request come from client then struts-config.xml file will loaded. Here we will learn how to configure struts-config.xml into web.xml.

 To configure struts-config.xml file into web.xml see following code action:-org.apache.struts.action.ActionServlet config:- /WEB-INF/struts-config.xml validating true. web.xml

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
http://java.sun.com/xml/ns/javaee/web-app_2_5.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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="loginForm" type="com.r4r.struts.LoginForm"/>
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="login" path="/login.do"/>
</global-forwards>
<action-mappings>
<action path="/login" type="com.r4r.struts.LoginAction" name="loginForm">
<forward name="success" path="/success.jsp"/>
<forward name="error" path="/error.jsp"/>
</action>
</action-mappings>
<message-resources parameter="com.r4r.struts.ApplicationResources"/>
</struts-config>

Here at time of Standard Action Servlet Configuration in web.xml we have to configure struts-config.xml.This is because load struts-config.xml at time of call ActionServlet . We can add more than one struts-config.xml file by creating sub-modules. e.g. Say we have two module report module and her module .

Previous Home Next