0

In the following web app structure, i am trying to put the init and context parameters from web.xml page to jsp page without making use of servlet.

index.html:

<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="action" method="get">
<a href="home.jsp">clik here</a></form>
</body>
</html>

web.xml:

<webapp>


<context-param>
<param-name>per1</param-name>
<param-value>val1</param-value>
</context-param>

<welcome-file>
index.jsp</welcome-file>

<servlet>
<servlet-name>abc</servlet-name>
<jsp-file>home.jsp</jsp-file>
<init-param>   
        <description>This is an init parameter example</description>   
        <param-name>InitParam</param-name>   
        <param-value>init param value</param-value>   
    </init-param>   
</servlet>

<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>action</url-pattern>
</servlet-mapping>

home.jsp:

<html>
<body>

 <%= application.getInitParameter("per1")%>
 <%= config.getInitParameter("InitParam") %>
  ${initParam.per1)
 </body>


 </html>

but i am not able to access these init and context parameters in my jsp page.

null null 

please let me know where i am getting wrong

Thanks

jayendra bhatt
  • 1,337
  • 2
  • 19
  • 41

1 Answers1

0

Your URL pattern and jsp name doesnt seem to match. Change those in web.xml

<servlet-name>abc</servlet-name>
<jsp-file>/home.jsp</jsp-file>
<init-param>   
        <description>This is an init parameter example</description>   
        <param-name>InitParam</param-name>   
        <param-value>init param value</param-value>   
    </init-param>   
</servlet>

<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/home.jsp</url-pattern>
</servlet-mapping>
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • i have mapped 'action' in the index.html to home.jsp and clik me link redirects the request to home.jsp. problem is the parameters are not read:( – jayendra bhatt Sep 26 '14 at 14:16