Create web.xml and struts-config.xml

To make struts based application. We need minimum two XMLs that are web.xml and struts-config.xml .The web.xml is a deployment descriptor file which is most impartent file.
For Struts based application we need one more file struts-config.xml file to configure actions of struts.
The web.xml file provides configuration and deployment information for the Web components that comprise a Web application. Web components are:-
·         Servlet parameters,
·         Servlet and JavaServer Pages (JSP) definitions, and
·         Uniform Resource Locators (URL) mappings.
In deployment descriptor we can describe following deployment descriptor elements
1.   ServletContext init parameters
2.   Localized context
3.   session configuration
4.   Servlet/JSP definitions
5.   Servlet/JSP mappings
6.   Tag Library
7.   MIME type
8.   Welcome file list
9.   Error pages
10.    Security information


A Sample Example of web.xml is for Servlet 2.4 application :

 Servlet 2.4 application wisedeveloper WelcomeServlet welcome /wisedeveloper.welcome wisedeveloper.welcome 404 /error404.html
The web.xml file must palaces into WEB-INF directory.
In struts based application we have to configure
1.   The Struts ActionServlet
2.   The struts tag libraries files
3.   The welcome files
4.   The error pages.
 and action org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml validating true 1 action *.do index.
jsp /taglibs/struts-tiles /WEB-INF/taglibs/struts-tiles.tld 404 /error404.html. The most important configuration in web.xml is configuring struts-config.xml.
We must have configured struts-config.xml (using the init-param tag) in web.xml with in ActionServlet configuration. e.g. action org.apache.struts.action.

ActionServlet config /WEB-INF/struts-config.xml …………….. ………Here we are mapping action servlet using two different url patterns..
 1. This will receives all requests coming from URL Pattern .do extension .This request is directed to ActionServlet action *.do e.g. http://localhost:8080/wisedeveloper/home .do this is directed to ActionServlet and ActionServlet Lookup home (URI )into struts-congif.xml called appropriate action. 
2. This will receives all requests coming from URL Pattern /pages/*.This request is directed to ActionServlet action /pages/* e.g. http://localhost:8080/wisedeveloper/pages/home
Note: These two ways are just only you can see URL pattern in browser and using this URL pattern you can request to server.
 When request is directed to ActionServlet then working will be same in both cases. struts-config.xml is most
important file in struts based application .We can use more than one struts-config.xml file into struts based application. The struts-config.xml can be placed in WEB-INF folder.
In struts-config.xml file we can configure ActionForm, Action ,DynaActionForm etc. All struts based components are configured here. 

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More