Ok,

I think there is one thing I NEED to do if I want to access the file as a
servlet resource.
Register the name of the flat file in the web.xml as init-param and access
it via ServletContext.

Am I right? I will try that but please do comment/correct on anything this
topic.

Thank you.


-----Original Message-----
From: Lyu, Paul 
Sent: Wednesday, October 23, 2002 10:26 AM
To: JDJList
Subject: [jdjlist] Accessing a flat file to be parsed from within a
servlet


Hello all,

I am currently working on converting our Servlet/JSP/JDBC application to be
J2EE compliant by moving away from pre-J2EE application server specific
proprietary method calls(in my case NAS40 app. server) and replacing them
with J2EE compliant calls(iAS6 SP2). 
During this exercise, I have identified the part of helper class code the
Servlet uses to read and parse a configuration file for the purpose of
initialization to be directory name dependant requiring it to be created
manually outside of the deployment process. 


Currently, the flat config. file is accessed and parsed as follows (by a
static method in a helper class):

line-1> String pathWithFileName =
System.GetProperty("ABSOLUTE_PATH_OF_APP_ROOT_DIR")+"/"+filename;
line-2>FileReader configFL = new FileReader(pathWithFileName);
line-3>Reader readBuffer = new BufferedReader(configFR);

// use tokenizeBuffer to parse..extract, etc

Because "pathWithFileName" evaluates to an absolute path on my current
machine where the code expects the config. file to reside, 
application now has a dependance on this particular directory.(e.g.
d:\sw\ias6\ias\APP\some_dir_name) 
I would like to think that this config. file can be accessed in a similar
manner as a jsp page is often accessed from within the servlet through the
(RequestDispatcher/ServletContext )for the purpose of 'forwarding', as
follows:


RequestDispatcher rd =
getServletContext().getRequestDispatcher(CONTEXT/JSP_FILE_NAME);

To me, being able to refer to a file in terms of the context path instead of
not its absolute path is a more desirable approach.


QUESTIONS===
(1)Can  something like this be done to access a flat file?? 
(2) I was wandering about the use of ServletContext.getResourceAsStream
(String path) method as a way to accomplish this.
However, the helper class where this happens does not have a ServletContext
since does not extend HttpServlet.


I look forward to anyone's help.

Thank you.

Paul










____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to