Reputation: 2287
I am trying to access initParameter
in my jsp.
When I try to access the initparameter
it is coming out as null.
My jsp page is:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String user=config.getInitParameter("User");
out.print("Hello "+user);
%>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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">
<display-name>
Learning</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>config</servlet-name>
<jsp-file>/config.jsp</jsp-file>
<init-param>
<param-name>User</param-name>
<param-value>Dummy</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>config</servlet-name>
<url-pattern>/config.jsp</url-pattern>
</servlet-mapping>
</web-app>
I am getting null while accessing init parameter. Please suggest.
Upvotes: 3
Views: 1068
Reputation: 1
The Name for jsp-file mentioned in the web.xml should be matched with the actual jsp file name in the WebContent example suppose you have /intipage.jsp in web.xml you need to carete initpage.jsp in the WebContent
Upvotes: 0
Reputation: 1338
If your JSP file name is config.jsp
it should work.
A case in which you can get a null value is when you write following:
<% String user=config.getInitParameter("User");
out.print("Hello "+user);%>
In JSP which is not config.jsp.
So please cross-check your JSP's name and It should be directly under WebContent in your project.
Upvotes: 3