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 Servlets and the fly likes I hava some question about servlet 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 » Java » Servlets
Bookmark "I hava some question about servlet" Watch "I hava some question about servlet" New topic
Author

I hava some question about servlet

quhao baggy
Greenhorn

Joined: Dec 10, 2003
Posts: 5
I'm a beginer about servlet, I'm studying SCWCD there is a question I con't
understand .
There is method getInitParameter(name:String)in class "ServletContext" ,the book show that the parameter "name" is the element between <param-name> and </param-name> in a " *.xml " . I don't understand:How can the Instance of the class ServletContext find the "name"? And how can an Inatance of class ServletContext link to a " *.xml" ?Hown can it know which is the parameter it need?
[ March 03, 2004: Message edited by: quhao baggy ]
Arnold Reuser
Ranch Hand

Joined: Nov 20, 2003
Posts: 194
Remember that a context-parm can be specified in the web.xml as follows :
<web-app>
....
<context-param>
<param-name>question</param-name>
<param-value>theAnswer</param-value>
</context-param>

.....
</web-app>
This context parameter can be retrieved using :
ServletContext httpServletContext = myHttpServlet.getServletContext();
String answer = httpServletContext .getInitParameter("question");
boolean b = "theAnswer".equals(answer); // true!!
 
wood burning stoves
 
subject: I hava some question about servlet
 
Similar Threads
ServletContext Vs ServletConfig
accessing ServletContext parameters
JWebplus Question ID :995984030593
wsdd urgent help
ServletConfig & Context ?