Two parameters can be defined in Web. xml:
(1) parameters within the application range are stored in servletcontext and configured in Web. XML as follows:
Context/Param Avalible during application
(2) servlet-specific parameters can only be obtained in the servlet Init () method. The configuration in Web. XML is as follows:
Mainservlet
Com. Wes. Controller. mainservlet
Param1 Avalible in servlet Init ()
0
In servlet, you can use the following code:
Package com. Wes. Controller;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Public class mainservlet extends httpservlet {
Public mainservlet (){
Super ();
}
Public void Init () throws servletexception {
System. Out. println ("the following two parameters param1 are stored in servlet ");
System. Out. println (this. getinitparameter ("param1 "));
System. Out. println ("the following parameters are stored in servletcontext ");
System. Out. println (getservletcontext (). getinitparameter ("context/Param "));
}
}