Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Servlet getInitParameters returns null.

843841Sep 23 2004 — edited Sep 24 2004
I've searched a bit through the forums and found this problem quite a bit but I never saw a really good explination on how to fix it. I have a servlet and I'm trying to get init parameters from my web XML. The servlet I have does not have an overridden Init function, In my web.xml I have a servlet name and I am calling the servlet using that name, i.e. I have a servlet named Foo and its class is com.foo.bar.Foo and I call it with /servlet/Foo. I have JSPs that I can use getInitParameter and everything works fine. I'm using Tomcat 5 on Windows 2000. My servlets are in a jar and the jar is in the common/lib directory. I know I'm doing something wrong but I'm not sure what it is, and its even more annoying that my JSPs work fine.

Also, another thing that should work but doesn't is that I'm trying to read a file on the server using
File newFile = new File(getServletContext().getRealPath("/images/pic.gif")); the get real path appears to contain the correct server side path to the image but the file can't be opened. If I do newFile.exists() or newFile.canRead() both return false. All examples that I have seen for reading files off the server seemed to use the getRealPath method so I assumed that would work.

Thanks.
Eudaemon.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2004
Added on Sep 23 2004
7 comments
242 views