Mapping JSP file in web.xml file with alias name

JSP file web.xml alias name

Giving alias name for a JSP file is optional. So far, we have executed all JSPs without alias name by writting the JSP file name in the action attribute of <form> tag. In this code, let us give alias name to JSP file and call it from action attribute.

I take this opportunity of using <init-param> tags in this example. The data placed in <init-param> is known as initialization parameters which can be read by the JSP when the JSP is loaded by the container. config object is used to read init parameter names. config is one of the 9 implicit objects, JSP supports.

In this program it is illustrated the use of config implicit object. config is an implicit object of ServletConfig interface of javax.servlet package. A Servlet configuration object is used by a Servlet container (a JSP is internally a Servlet) to pass information to a Servlet during initialization.

Example on JSP file web.xml alias name

File Name: InitData.jsp

<%@ page import="java.util.*" %>

The JSP Name: <%= config.getServletName( ) %> <% Enumeration e = config.getInitParameterNames( ); while(e.hasMoreElements( )) { String name = (String) e.nextElement(); String value = config.getInitParameter(name); out.println("
" + name + " : " + value ); } %>

Copy the InitData.jsp as usual to india directory; but write the following code in the web.xml file(generally we don’t write web.xml for JSP files).

      Config Software Solutions
      S N Rao

Important Note (on JSP file web.xml alias name)

Default Setting : <servlet-class> something </servlet-class>
Replace completely with : <jsp-file>InitData.jsp</jsp-file>

(Remaining settings just over write with your values as you do it in Servlets. Only the above statement needs complete replacement)

Run the Tomcat.

As this JSP file does not have client progrm, type the following statement in the browser prompt and exeucute.


Leave a Comment

Your email address will not be published.