top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

When will Container initialize multiple JSP/Servlet Objects?

0 votes
363 views
When will Container initialize multiple JSP/Servlet Objects?
posted Sep 15, 2017 by Pooja Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

If we have multiple servlet and servlet-mapping elements in deployment descriptor for a single servlet or JSP page, then container will initialize an object for each of the element and all of these instances will have their own ServletConfig object and init params.

For example, if we configure a single JSP page in web.xml like below.

<servlet>
  <servlet-name>Test</servlet-name>
  <jsp-file>/WEB-INF/test.jsp</jsp-file>
  <init-param>
    <param-name>test</param-name>
    <param-value>Test Value</param-value>
  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>Test</servlet-name>
  <url-pattern>/Test.do</url-pattern>
</servlet-mapping>

<servlet>
  <servlet-name>Test1</servlet-name>
  <jsp-file>/WEB-INF/test.jsp</jsp-file>
</servlet>

<servlet-mapping>
  <servlet-name>Test1</servlet-name>
  <url-pattern>/Test1.do</url-pattern>
</servlet-mapping>

Then if we can access same JSP page with both the URI pattern and both will have their own init params values.

answer Sep 16, 2017 by Ayush Srivastav
Similar Questions
+1 vote

I have a JSP with a layout. it means the JSP has menu on the left and header on the top. now for every action the center part of the JSP should change. Is this possible?

I mean for every different action a different JSP should be included in the center of the layout JSP. If this is possible it will be of so much help. kindly help? if possible is there a solution without tiles?

...