• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

deployment descriptor

 
ricky gonzalez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have some questions about the deployment descriptor.
What are the servlet context initialization parameters, and what do they do in an application?
What are the differences between the fields <context-param> and <init-param>?
Thanks.

 
Doshi Milan
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I would really appreciate if someone gives some more info on this.
Thanx,
Milan
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow... a really old original post.
And the following servlet uses these intialization parameters. It also places them in a context that JSP's can use them as Application level variables.

p.s. - I really dislike how this forum software removes blank lines. Makes code examples hard to read.
[This message has been edited by Mike Curwen (edited May 29, 2001).]
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ricky,
<init-param> is tied to a single servlet wheras <context-param> is tied to ALL servlets and ALL jsps in one whole application.
Mike's way is ti use a <init-param> as <context-param>. Since <init-param> is known for one servlet only, we have to take special steps to put them in servletContext so that they can be accessed globally in all servlets and jsps of that web application.
regds
maha anna
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maha,

I didn't realize something until you pointed it out. Which seems silly on my part, because I should have realized it.. I even said "application level for jsp". I thought by obtaining the servlet context, and then use setAttribute on that context, that it means the variables are global to the servlet, and that servlet only. But it appears to not be true. I have three servlets within my J2EE application, so I will test that out today, and see if I can set these variables in one servlet, and have them usable from another.

p.s - when I edited my original post, I only saw today another buggy behaviour of this forum software... if you use the [ quote ] tags, they disappear from your post after editing. I originally had two quotes from the J2EE help files regarding context and init params. I will have to stick with [ code ] tags from now on.
 
Doshi Milan
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike/Maha for the reply.
But I am getting a weird probelem.
I am not able to retrieve the init parameter. I am getting Null.

My code in the web.xml (in tomcat 3.2.1) is as follows:
:
<servlet>
<servlet-name>Demo1</servlet-name>
<servlet-class>Demo1</servlet-class>
<init-param>
<param-name>Name</param-name>
<param-value>Mike</param-value>
</init-param>
</servlet>
:
In case of my servlets file this is what I have
public class Demo1 extends HttpServlet {
String N1= null;

public void init(ServletConfig config) throws ServletException {
super.init(config);
N1= config.getInitParameter("Name");
System.out.println("N1 is "+N1);
:
:
}
}
The o/p is N1 is null.
Is it anything to do with my setup,
i.e Jdk1.2.2, JSDK2.0 , tomcat 3.2.1.
Thanks.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That does seem very strange.

Everything looks fine. If you have directly copy and pasted it is fine, but if not, makes sure your "Name" string exactly matches each other. eg: Don't have "Name " in the web.xml and "Name" (no space) in the servlet.

Otherwise, I can't see the problem.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ricky,
Did you include these lines in your web.xml. The <url-pattern> is a must to associate init-param pass init-params to a servlet. Otherwise the servlet is unaware of the configuration of init params in web.xml.

PLease refer to Preethi's 3rd doubt in this following discussion.
http://www.javaranch.com/ubb/Forum7/HTML/003517.html
regds
maha anna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic