| 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...
|
 |
 |
|
|
subject: Problem in reading Servlet's Init parameters!
|
|
|