Naveen Chauhan
Naveen Chauhan

Reputation: 2026

How to retrieve jsp init parameter

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
  <servlet-name>InitializationJSP</servlet-name>
  <jsp-file>/initialization.jsp</jsp-file>
  <init-param>
    <param-name>testParam</param-name>
    <param-value>hello from web.xml</param-value>
  </init-param>
</servlet>
<servlet-mapping>
  <servlet-name>InitializationJSP</servlet-name>
  <url-pattern>/Initialization</url-pattern>
</servlet-mapping>
</web-app>

initialization.jsp

<html>
<head>
<title>Initialization Parameters and JSP</title>
</head>
<body>
This page has retrieved the following initialization parameter from web.xml:
<br>
<%= pageContext.getServletConfig().getInitParameter("testParam") %>
</body>
</html>

My directory structure is

sample
   Initialization.jsp
   WEB-INF
      web.xml
      classes/
      lib/

Is there any problem? This jsp file is not running when i run this using tomcat and appending /initialization after the application url.

Upvotes: 0

Views: 2600

Answers (1)

Siva Charan
Siva Charan

Reputation: 18064

change this
<jsp-file>/initialization.jsp</jsp-file>
to
<jsp-file>/Initialization.jsp</jsp-file>

Upvotes: 1

Related Questions