This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hello,
In developing my web application i have used a file to register and search data
the is stored beside the class that do the operations of reading and writing
well, when i write the name of the file as a path for it as follow
Web apps have no concept of a "default directory", so you can't use relative paths for files. You either need to use absolute paths, or -for directories inside your web app directory- use ServletContext.getRealPath(...).
Oh, now I see it's about the compiler error - "new File(...)" throws that exception, so you need to handle it properly (using a try/catch block).
Get the stream at the servlet level and pass it to the normal class.
There's no way that your "normal" class can determine the location of the file (unless the full path is hard-coded -- not a good idea) without the help of the servlet layer.
Or, place the file somewhere in the classpath and use ClassLoader.getResourceAsStream().
Or, store the absolute path of the file in a properties file that you read at run time.
this class will search in the file about the username and password specified
and if found it return a User object that will be put in the session later
Roger Fed wrote:this class will search in the file about the username and password specified
and if found it return a User object that will be put in the session later
What's in the file that needs to be looked up? Is this not something better handled by a database?
In my opinion you are spending a lot of time trying to do things the wrong way, and that time would be better spent learning the skills you lack to do it the right away.
If you're just using this for a learning experience (your reasoning for not wanting to involve a database), you may want to consider making the username / password either servlet init parameters, or context parameters for the web application. DO NOT DO THIS WITH A SECURE PASSWORD, but if you want to use it just for testing, this might be a good approach.
Bear's right. For an actual enterprise solution, a database (or LDAP server) is a better option.
OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.