| Author |
Call text file in init() method
|
Sham Jowsaki
Ranch Hand
Joined: May 22, 2001
Posts: 146
|
|
Hi all, I need to call a text file (.txt) only one time in my servlet while servlet start (I meant init() method) which contains user info. From that I need to verify the user info in service or dopost method by referring the above text file irrespective of calling the text file everytime in the service method. Pls advise me.. how to achieve my task. Thanks Cheers jowsaki
|
 |
Mark Howard
Ranch Hand
Joined: Feb 14, 2001
Posts: 285
|
|
Hi Sham It may be worth considering using initial parameters for your servlet, which you configure in your web application's deployment descriptor (web.xml) file using <init-param> tags. You then retrieve these parameters using the ServletConfig's getInitParameter("param name") method in your servlet's init() method. Hope this helps Mark.
|
 |
Sham Jowsaki
Ranch Hand
Joined: May 22, 2001
Posts: 146
|
|
Hi mark, Do i need to call below <web-app> <servlet> <servlet-name>Controller</servlet-name> <display-name>Controller</display-name> <servlet-class>ControllerServlet</servlet-class> <init-param> <param-name>ActionConfig</param-name> <param-value>config.txt</param-value> </init-param> </servlet> If it is correct pls advise me below points (a) where do i need to keep config.txt and (b)How can invoke the filereader object(above text file) in my service or dopost method. Pls advise me tks a lot jowsaki
|
 |
Mark Howard
Ranch Hand
Joined: Feb 14, 2001
Posts: 285
|
|
Hi Sham What I meant was to use init parameters instead of an external file. Or does the file contain a lot of data too cumbersome to place in the deployment descriptor?
|
 |
Asher Tarnopolski
Ranch Hand
Joined: Jul 28, 2001
Posts: 260
|
|
|
in any case, if you'll decide to use init params or text file, you don't have to punish the first user who will enter your servlet and will have to wait until your file will be read and the parameters will be run as you want. you can use <load-on-startup> tag and your servlet will be initialated and its init method will be called when your servlet will start.
|
Asher Tarnopolski
SCJP,SCWCD
|
 |
 |
|
|
subject: Call text file in init() method
|
|
|