File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in reading Servlet's Init parameters!

 
Vanchi Nathan
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Praful Thakare
Ranch Hand
Posts: 642
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have NOT given any value in <param-value></param-value>..
it must be some integer value as ur Using Integer.parseInt..
Cheers
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic