This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes question--Initializing JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "question--Initializing JSP" Watch "question--Initializing JSP" New topic
Author

question--Initializing JSP

Anna Wang
Ranch Hand

Joined: May 26, 2006
Posts: 30
Hello,everyone,

In HFSJ (p. 308), about initializing JSP, I am not very clear about that. How can I do servlet initialization stuff in JSP.

I wrote part of the codes, can anybody add more to finish it.

From the book and errara.
The web.xml is:
-----------------------------
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>JspInit</servlet-name>
<jsp-file>/TestInit.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>annawang@yahoo.com</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyTestInit</servlet-name>
<url-pattern>/TestInit.jsp</url-pattern>
</servlet-mapping>
</web-app>
-------------------------------

TestInit.jsp is:
----------------------------
<html>
<body>

<%!
public void jspInit() {
ServletConfig sConfig = getServletConfig();
String e = sConfig.getInitParameter("email");
ServletContext ctx = getServletContext();
ctx.setAttribute("mail", e);
}
%>

The email address is: ???

</body>
</html>

-----------------
How to write next to output: annawang@yahoo.com?

Thank you very much.

Anna
Gaurav Gambhir
Ranch Hand

Joined: Mar 04, 2006
Posts: 254
Related Thread
Karne Reddy
Ranch Hand

Joined: May 28, 2006
Posts: 35
Hi Anna,
U can print the email by
${applicationScope.mail}

or

If u have not ovverrided the jspInit() method , u can display it
by <%=config.getInitParameter("email")%>
(config is implicit varialble)


asdfa
Anna Wang
Ranch Hand

Joined: May 26, 2006
Posts: 30
Thank you very much for the answers. It is very clear.

Anna
salil verma
Greenhorn

Joined: Jun 03, 2006
Posts: 22
Hi Karne,
applicationScope is a map of attribures of context so ${applicationScope.mail} would not work for printing the config parameters.
although <%=config.getInitParameter("email")%> will fairely work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question--Initializing JSP
 
Similar Threads
Problem with jspInit() overriding
Access Servlet InitParameters in JSP
Regarding jspInit() overriding
implicit object config
Trouble with application attribute / jspInit...