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 .

2 comments:

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic