Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

DD elements <context-param> and <init-param> both can be retrieved by the getInitParameter() method, in the servlet code.

Now the question is, how does it differentiate <context-param> and <init-param>?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

Servlet init parameters are for a single servlet only. Nothing outside that servlet can access that. It is declared inside the <servlet> tag of Deployment Descriptor, on the other hand context init parameter is for the entire web application. Any servlet or JSP in that web application can access context init parameter. Context parameters are declared in a tag <context-param> directly inside the <web-app> tag.

The methods for accessing context init parameter is

getServletContext().getInitParameter("name"); 

whereas the method for accessing servlet init parameter is

getServletConfig().getInitParameter("name");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...