As ActionServlet is simple Servlet class only but designed using the Front Controller Design Patern so it must be configured in the web.xml file at the container itself only, so that every request must be followed by ActionServlet.

Web.xml file

<servlet>

  <servlet-name>login</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>

  <load-on-startup>1</load-on-startup>

</servlet>
  
  <servlet-mapping>

   <servlet-name>login</servlet-name>
   <url-pattern>*.do</url-pattern>
  
  </servlet-mapping>

Here we have configured the ActionServlet class of org.apache.struts.action package under the servlet tag.

Why we are configuring ActionServlet at the container start-up ?

It is because first request handled by this servlet only then control will go to the RequestProcessor and then to our own Action class, so that we need not to design as many Servlet class for as many Actions. In Front Controller Design Pattern all the request get handled by only one servlet and once ActionServlet get initialized it is able to handle all the incoming request from the client machine. 

This is the also reason why we are mentioned load-on-startup value as 1 because it get initialized at the container start-up only. 

Why we hard-coded the "config" in the init-param tag ?

It is because config is also hard-coded in the init() method of the ActionServlet so that it can be able to get the name of the struts-config.xml file and able to parse and load to the main memory.   

Is struts-config.xml is fixed file name ?

No it in not a fixed name, we can have any name but need to configure in the param-value tag in the web.xml file. 

Why we have written *.do in the url-pattern ?

*.do indicate that for all the incoming request there is only servlet class i.e ActionServlet class. But we can have any suffix instead of .do .

Related Posts:

  • Introduction to Struts 1 Most importantly Struts 1 is a web framework which is internally implemented using Servlet and JSP technologies. This web framework is designed by Apache Software Foundation in 2001 keeping in view to reduce the task of the… Read More
  • What Happen after Container start-up in Struts based Application Following task are performed at the Container start-up in Struts based Application. They are : 1. Container make sure about the web configuration file i.e web.xml whether is available or not. 2. If not available then C… Read More
  • How Request Handled By ActionServlet ? All the Request by the client are get processed by the ActionServlet only then get forwarded to the Request Processor. ActionServlet is a single Servlet designed by the Apache using Front Controller Design Pattern. It fo… Read More
  • First Struts 1 Example Using Eclipse Steps to follow for developing Struts Application using Eclipse :- We must have to follow some of the basic steps to develop any struts application using the Eclipse IDE. 1. Create Dynamic Web Project. 2. Copy all the… Read More
  • Implementing execute() with HTTP request in Struts We can write our own Action class using Struts framework but need to extends Action class of org.apache.struts.action package and need to override execute() method which return the ActionForward class object and which must… Read More

2 comments:

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201978

Online Members

Live Traffic