Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

i get ' null ' for jsp init params

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops! your right

thank you
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic