File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) 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 » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Initializing your JSP" Watch "Initializing your JSP" New topic
Author

Initializing your JSP

Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 78
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.

<servlet>
<servlet-name>MyTestInit</servlet-name>
<jsp-file>/TestInit.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>djabonete@gmail.com</param-value>
</init-param>
</servlet>

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"));
}
%>
<html>
<head>
<title>JSP Init Test Page</title>
</head>
<body>
<%= getServletContext().getAttribute("mail") %>
</body>
</html>

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

Joined: Jul 20, 2005
Posts: 10290
    
168

Please dont post the same question in more than one forum. Let's continue the discussion in your other post.


[My Blog] [JavaRanch Journal]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Initializing your JSP