• Post Reply Bookmark Topic Watch Topic
  • New Topic

i get ' null ' for jsp init params  RSS feed

 
janne s
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls, can anyone help me with this....

i set init parameters of jsp (as on HFS pg:308) and servlet in DD. servlet init pramas are retrieved correctly...where as for jsp i get 'NULL'. Following are the DD and JSP page . I'm using Tomcat 5.0.19..
try to restart the server still no change in the result.


DD

<web-app>

<servlet>

<servlet-name> Beer </servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>

<init-param>
<param-name>adminEmail</param-name>
<param-value>admin@gmail.com</param-value>
</init-param>

</servlet>


<servlet>
<servlet-name>Hobby</servlet-name>
<servlet-class>com.example.web.HobbyServlet</servlet-class>
</servlet>


<servlet>

<servlet-name>MyJSPServlet </servlet-name>
<jsp-file>/MyJsp.jsp</jsp-file>

<init-param>
<param-name>email</param-name>
<param-value>admin@yahoo.com</param-value>
</init-param>

</servlet>


<servlet-mapping>
<servlet-name>Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>


<servlet-mapping>
<servlet-name>Hobby</servlet-name>
<url-pattern>/HobbyPage.do</url-pattern>
</servlet-mapping>

</web-app>

----------------------------------

JSP PAGE

<%@ page import="java.util.* , javax.servlet.* , javax.servlet.http.* " %>

<HTML>
<body>
<h2> Select your Hobby </H2>

<form method ="POST" action = "HobbyPage.do">
Choose a Hobby:<p>

<select name="hobby" size="1">
<option>Horse Skiing</option>
<option>Extreme Knitting</option>
<option >Alpine Scuba</option>
<option >Speed Dating</option>
</select>
<br><br>
<center>
<input type="SUBMIT" value="submit">
</center>
</form>

<%!
public void jspInit()

{

ServletConfig sc = getServletConfig();
String mail = sc.getInitParameter("email");
ServletContext ctx = getServletContext();
ctx.setAttribute("id",mail);
}
%>



Email : <%= application.getAttribute("id") %>
</body>
</html>


Thanks in advance
jaya
 
Ritu varada
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where is the servlet mapping for the below

<servlet-name>MyJSPServlet </servlet-name>

Could that be a problem ?
 
janne s
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops! your right

thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!