aspose file tools*
The moose likes Servlets and the fly likes Problem in reading Servlet's Init parameters! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in reading Servlet Watch "Problem in reading Servlet New topic
Author

Problem in reading Servlet's Init parameters!

Vanchi Nathan
Ranch Hand

Joined: Feb 24, 2004
Posts: 107
Hello there!

I am trying to read a variable 'repeats' from the web.xml file into the servlet. The problem is when i try to overwrite its value, when not given in the <param-value> element, to a hardcoded value say 3.

See code below:
===============
(web.xml)

<servlet>
<servlet-name>testInitPara</servlet-name>
<servlet-class>vlv.mserver.others.TestInitPara</servlet-class>
<init-param>
<param-name>repeats</param-name>
<param-value></param-value>
</init-param>
</servlet>
=================
(servlet code in init method)
...
private String times;
private int repeats;
...
//(inside init method)
...
try {
times = cfg.getInitParameter("repeats");
repeats = Integer.parseInt(times);
} catch (NumberFormatException e) {
repeats = 3;
}
...
====================

Is there any thing wrong in the above code. Pl. help


Best regards,<br /> <br />vanchin
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 613
you have NOT given any value in <param-value></param-value>..
it must be some integer value as ur Using Integer.parseInt..
Cheers


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Vanchi Nathan
Ranch Hand

Joined: Feb 24, 2004
Posts: 107
Hello,

As per the code shown, it throws a NumberFormatException because the value is "" (empty string). This should execute the catch block, and assign the value '3', but it doesn't assign this value.

Pl. help...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in reading Servlet's Init parameters!
 
Similar Threads
Multiple Struts-config.xml in Jboss 4.2.1
Servlet can't find intialisation paramters
who can help me in a example
problem with web.xml and the getinitParameter() func
Initparameter not working