Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Cannot find Find Properties File

 
Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem occurs when attempting to load a properties file in a servlet.

The batch job works OK. So I cut and paste the batch driver (GBTest01) into the servlet.

The servlet fails :


What's missing ? Thank you for any help.

The Properties File Directory :


The Classpath : C:\apache-tomcat-6.0.18\webapps\GBForms is in the classpath (the batch program found it).

The Batch Driver :

The Properties File Loader : used by batch and servlet

The Servlet :
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Servlet containers like Tomcat ignore your environment CLASSPATH - look at the class-loader-howto.html file normally installed with Tomcat in the "docs" under webapps.

2. The servlet API provides a mechanism for locating files in the web application. See javax.servlet.ServletContext API for methods like getContextPath, getRealPath.

Bill
 
Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply.
By tinkering around I found that placing the properties file in WEB-INF/classes works.
I will read the documentation.
Graeme.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic