It's not a secret anymore!
The moose likes JSP and the fly likes Initializing your JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Initializing your JSP" Watch "Initializing your JSP" New topic

Initializing your JSP

Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 84
Greetings Ranchers!

I�ve run through some confusion in Overriding jspInit() method. I am using the Head First book. I�ve followed the instruction in the book in configuring the servlet init parameter then inserted the <jsp-file> element in th DD.


Then my jsp:

public void jspInit() {

ServletConfig sConfig = getServletConfig();
java.util.Enumeration e = sConfig.getInitParameterNames();
while(e.hasMoreElements()) {
System.out.println("sConfig = " + e.nextElement().toString());
String emailAddr = sConfig.getInitParameter("email");

ServletContext ctx = getServletContext();
ctx.log("emailAddr = " + emailAddr);
ctx.setAttribute("mail", emailAddr);

System.out.println("jspInit has been Initialized");
System.out.println("ctx.getAttribute(\"mail\") = " + ctx.getAttribute("mail"));
<title>JSP Init Test Page</title>
<%= getServletContext().getAttribute("mail") %>

I did get the �mail� attribute sets in the Context. I would really appreciate your help. Thank you very much!
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The easiest way to test this would be to copy this line:
<%= getServletContext().getAttribute("mail") %>
to a new JSP and hit it after hitting your other one.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 84
Got it!

It also need <servlet-mapping> in the DD;


I agree. Here's the link:
subject: Initializing your JSP
jQuery in Action, 3rd edition