Cannot read Property file from JSP in a Web Module Project

I have tried to read the properties file in two ways but am not able to read it because i cannot find the correct path of the properties file.
1st Method :
Properties props = new Properties();
InputStream is =
application.getResourceAsStream(
"test.properties");
if (is != null) {
props.load(is);
is.close();
Enumeration keysEnum = Props.propertyNames();
while (keysEnum.hasMoreElements()) {
out.println(keysEnum.nextElement()) ;
2nd Method :
Here "com.sap.package" is the package name and "test" is the Properties file name
ResourceBundlebundle = ResourceBundle.getBundle("com.sap.package.test");
for (Enumeration e = bundle.getKeys(); e.hasMoreElements();)
String key = (String) e.nextElement();
out.print((String) e.nextElement());
String s = bundle.getString(key);
request.getComponentSession().putValue(key, s);
I cannot read the properties file even when I keep in it the WEB-INF folder.

Properties props = new Properties();
InputStream is = this.class.getClassLoader().getResourceAsStream(/test.properties);
if(is != null){
props.load(is);
Keep the test.properties in the classes folder under the web-inf folder.
Thanks,
Tim

Similar Messages

  • Cannot seem to read properties file from JSP

    Hi all,
    In an ISA 4.0 application I want to read a properties file from a JSP to decide whether or not to execute some specific JavaScript code. I want the properties file because in it I can easily configure this externally. I put my properties file in /WEB-INF/classes.
    I develop on an environment using Tomcat where this works fine. On an acceptance machine using the SAP J2EE engine however this won't work, to my surprise. Can anyone give me a suggestion on why my properties file is not read?
    Here's the Java scriptlet code:
    UserSessionData userSessionData = UserSessionData.getUserSessionData(session);
    // theme will be something like "themes/zester":
    String theme = (String) userSessionData.getAttribute(Constants.THEME_KEY);
    boolean showScript = false;
    int slashIndex = theme.indexOf('/');
    String themeKey = null;
    // get the "zester"-like part from the theme:
    if(theme != null && slashIndex > -1) {
      themeKey = theme.substring(slashIndex + 1);
    Properties props = new Properties();
    InputStream is = application.getResourceAsStream("/WEB-INF/classes/script.properties");
    if(is != null) {
      props.load(is);
      is.close();
      Enumeration keysEnum = scriptProps.propertyNames();
      while (themeKey != null && keysEnum.hasMoreElements()) {
       if(theme.toUpperCase().endsWith((String) keysEnum.nextElement())) {
        showScript = true;
        break;
       showScript = false;

    Hi Kishor,
    Thank you for taking the time!
    I agree, this issue may have to do with the deployment. There is however a remark in the <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html">ServletContext</a>  interface documentation on methods <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html#getResource(java.lang.String)">getResource()</a> and <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String)">getResourceAsStream()</a> that may also be of interest here:
    "The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource."
    Is this remark of relevance to the subject, or is this thought too far fetched? Mind you, the documentation also states that "This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file". It should, therefore, be possible to read a file from disk???
    Cheers,
    Peter-Jan Bosch

  • Cannot read backup file from PC on Mac

    I am trying to move my Photoshop Elements 9 catalog from my PC to my Mac.
    I have backed up the catalog to an external HDD but when I connect it to the Mac I can see the folder but I cannot open it. The backup is big, over 200GB, could this be the problem? I have several other backups on the same HDD but the MAC cannot read any of them.
    I can open the folders without any problem on a PC.
    I took the HDD to a Mac "Genius Bar" and they could not open the folders on their Mac either and had no idea what could be causing the problem.
    I had no problem migrating to the Mac about a year ago when I first got it, but I suppose the backup would have been smaller then.
    Has anybody got any idea what the problem could be

    In the Backup folder, there is a Backup.tly file which needs to be specifically seleted while restoring the backup. So while you go for File >Restore catalog > try to choose All files from the format dropdown to see this tly file.
    Thanks
    Andaleeb

  • Read xml file from jsp/servlet

    Hi all,
    I am a new comer to jsp and really appreciate if someone can help me on this:
    I will like to use a xml file to control access to my web app instead of using a database. Let say user.xml that will contains user name and password. Questions:
    1. where should I put this file? Under WEB-INF?
    2. In my jsp or servlet, how do i read the xml file, i mean how to i refer to the file (depend on question 1 as where the file should be placed)?
    Thank you very much.
    Sim

    Hi jlsim,
    you can place the xml file where you want, but remember that placing it under /WEB-INF is the most security way.
    I had a similar problem and I placed the xml file under /WEB-INF directory.
    To refer to it I did something like this:
    String realPath=getServletContext().getRealPath("WEB-INF/xml/workspaces.xml");//obtain the real path
    File f=new File(realPath);//obtain an instance of your file usable
    //to create an InputStream

  • Elements 10, cannot read cr2 files from EOS 6D, anyone else have this issue?

    Sorry my discussion topic is my question. Followed by if so, how did you fix it or what suggestions do you have? Thank you.

    You need PSE11 or PSE12 for the 6D. You may wish to wait to upgrade to the forthcoming PSE13. Or consider the Photography Plan – Lightroom + full Photoshop for $9.99 pm (or local currency.)Alternatively, download and install the free Adobe DNG converter to convert your CR2 files to the Adobe universal Raw format and the files will open in PSE10(keep your originals as backups and for use in the camera manufactures software)
    Windows download (.exe file) click here DNG Converter 8.6
    Mac download (.dmg file) click here DNG Converter 8.6
    You can convert a whole folder of raw images in one click. See this quick video tutorial:
    You Tube click here for DNG Converter tutorial

  • When will we be able to read NEF files from a NIKON 5200?

    Just got a Nikon D5200. Photoshop and Bridge cannot read NEF files from this camera. It worked fine with my D3100 camera. When will we be able to read NEF files from a NIKON 5200?

    Welcome to the forum!
    As often, we cannot give a simple answer without more informations: what version of Photoshop and Bridge are you talking about?
    The rule of thumb is to update Camera Raw to the latests version compatible with Photoshop, and if it does not work, to download the last version of the DNG converter and use it on the files to convert them to DNG that can be opened in the older versions of Camera Raw and other raw converters.
    Normally, to update go to Help>Updates...
    According to http://helpx.adobe.com/creative-suite/kb/camera-raw-plug-supported-cameras.htmlhe first version of Camera Raw that can open the NEF from the 5200 is Camera Raw 7.3, that works with Photoshop CS6. If you version of Photoshop is older, you'll need to use the DNG converter 7.4:
    (but, since you don't state what operating system you are using, here are the links for both versions:
    PC http://www.adobe.com/support/downloads/product.jsp?product=106&platform=Windows
    Mac: http://www.adobe.com/support/downloads/product.jsp?product=106&platform=Macintosh )

  • When I open iPhoto 9.2.1 it says that my library needs to be upgraded but when I upgrade the library I am trying to open (33 GB worth of pictures from 2006) the new application says it cannot read the files and how to find them on the system to reimport?!

    When I open iPhoto 9.2.1 it says that my library needs to be upgraded but when I upgrade the library I am trying to open (33 GB worth of pictures from 2006) the new application says it cannot read the files and how to find them on the system to reimport?! and then I'd like to erase the original files since the space requirement is huge!!!! Why is upgrading software iPhoto such a pain. I've gotta get a presentation done and all I get for my money is roadblock!!!

    hello, it sounds like the library is damaged.
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. 

  • I cannot open pdf files from one supplier when using Adobe Reader but I can using another Viewer

    I cannot open pdf files from one supplier when using Adobe Reader but I can open it if using Google PDF viewer or another viewer. The Adobe reader gives the error "There was an error opening this document. The file is damaged and could not be repaired" when I try to open the file. The version of Adobe Reader is 10.1.7, however I have tried other versions and they all fail the same way.  I have tested on a number of different PC's in different networks and all fail using Adobe Reader but work using alternate viewer. Also the PC's will open a PDF from any other source.

    Newer Reader versions are more strict than older versions (and other PDF viewers).  If certain minimum requirements are not met, Reader will tell you that the PDF is damaged.  This can happen when a document was created with software that does not adhere to PDF standards, or when the file was damaged during a download or email transmission.
    You should contact the creator of these PDFs.

  • FILENOTFOUNDEXCEPTION while reading property files in Tomcat 6------Help me

    Hi All
    I am planning to migrate my web application from iplanet 4.1 to tomcat 6. In this process I need to read the properties files initially.
    for eg: i got the property files in a iPlanet:
    Config directory---
    abc.properties.---
    abc.log--
    In tomcat I configured them in web.xml saying that.
    <servlet>
    <servlet-name>ABC</servlet-name>
    <servlet-class>com.ijk.abc</servlet-class>
    <init-param>
    <param-name>Loan</param-name>
    <param-value>/WEB-INF/config</param-value>
    </init-param>
    <init-param>
    <param-name>loan.props</param-name>
    <param-value>/WEB-INF/config/abc.props</param-value>
    </init-param>
    <init-param>
    <param-name>loan.log</param-name>
    <param-value>/WEB-INF/config/abc.log</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>ABC</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    I need to read initially all the property files and then proceed.
    While configuring in this way, it am getting error saying that
    abc.props or abc.log..............(FILE NOT FOUND EXCEPTION)
    Can anyone suggest me how to configure them.
    Thanks in Advance.

    Thanks for your response, Actually we dont have the source code for that because it is very old code, but i m using decompiler in which i can get some informtaion.
    OS used for iPlanet is Unix but now I need to deploy this application in tomcat in windows server 2003.
    Servlet clss:
    SERVLET CLASS:
    Class com.ijk.abc implements extends HttpServlet  implements PropertyKeys
    private IClickManager m_im;
    public void init(ServletConfig paramServletConfig)
        throws ServletException
        Utils.info("Servlet initialization");
        try {
          super.init(paramServletConfig);
          Utils.info("ServerInfo: " + getServletContext().getServerInfo());
          PGroup localPGroup = this.m_im.claimPG();
          Utils.trace("Got " + localProcessorGroup + " for initialization");
          this.m_im.gatherProperties(localProcessorGroup);-----------this is where it is calling the property files.
          this.m_im.freePG(localPGroup);
          Utils.trace("Released " + localPGroup + " for new Properties");
          localPGroup = this.m_im.claimPG();
          Utils.trace("Got " + localPGroup + " for new Properties");
          try
            ConHandler localDBHandler = (ConHandler)localPGroup.getDBHandler("config.dbhandler");
            this.m_im.setNumPGs(localDBHandler.getNumPGroups());
          catch (Exception localException1) {
            Utils.info("NON FATAL ERROR: failed to set number of PGs", localException1);
          try
            Session.createAndStartSessionTask(localPGroup);
            localPGroup.resumeAllTasks();
          catch (Exception localException2) {
            Utils.info("NON FATAL ERROR: failed to start tasks", localException2);
          this.m_im.freePG(localPGroup);
          Utils.trace("Released " + localPGroup + " for initialization");
          Utils.info("Servlet initialization finished");
        catch (FatalServletError localFatalServletError) {
          Utils.error("FatalServletError: ", localFatalServletError);
          throw new UnavailableException(this, localFatalServletError.toString());
        catch (Error localError) {
          Utils.error("Error: ", localError);
          throw localError;
    ==========================================================
    public void gatherProperties(ProcessorGroup paramProcessorGroup)
        Object localObject;
        this.m_props.clear();
        String str1 = this.m_servlet.getInitParameter("loan.dir");
        if (str1 == null) {
          str1 = System.getProperty("server.root", System.getProperty("user.dir", "."));
        this.m_props.put("loan.dir", str1);
        String str2 = this.m_servlet.getInitParameter("abc.log");
        setLogFile(str2);
        try
          String str3 = this.m_servlet.getInitParameter("abc.props");
          if (str3 == null)
            str3 = "abc.props";
          localObject = str1 + File.separator + str3;
          Utils.info("Reading properties from file: " + ((String)localObject));
          Utils.loadProperties(this.m_props, new BufferedInputStream(new FileInputStream((String)localObject)));
        catch (IOException localIOException) {
          Utils.info("NON FATAL WARNING: Could not read props file", localIOException);--while running i m getting this error
        Utils.info("Reading properties from Servlet Parameters");
        Enumeration localEnumeration = this.m_servlet.getInitParameterNames();
        while (localEnumeration.hasMoreElements()) {
          localObject = (String)localEnumeration.nextElement();
          this.m_props.put(localObject, this.m_servlet.getInitParameter((String)localObject));
        Utils.info("Reading properties from DB");
        try {
          localObject = (ConDBHandler)paramProcessorGroup.getDBHandler("config.dbhandler");
          String str5 = ((ConDBHandler)localObject).getPropertiesFile();
          Utils.loadProperties(this.m_props, new ByteArrayInputStream(str5.getBytes()));
        catch (Exception localException) {
          Utils.info("NON FATAL WARNING: Could not read props file", localIOException);--while running i m getting this error
        String str4 = this.m_props.getProperty("smtp.host");
        if (str4 != null) MailUtils.setSMTPHost(str4.trim());
        if (str2 == null) {
          str2 = this.m_props.getProperty("abc.log");
          setLogFile(str2);
         runInitializers(paramPGroup);
        Utils.info("New Properties:", this.m_props);
        this.m_rroots = StringUtils.getPathsFromList(this.m_props.getProperty("resource.path", "/com/loan/resources/:/"));
        clearAllPGs();
    =================================================================
    the above is the servlet class and the method which is using to read the property files from root directory in Unix.
    ie../opt/mywebapp/loan/abc.props,abc.log
    loan is the directory in which two property files are placed.
    i just want to where to place property files in tomcat so that its going to read the property files.
    Right now, i placing it in the WEBAPPS/MYWEBAPPLICATION/WEB-INF/LOAN/abc.props,abc.logs.
    Its giving me errors such as FILENOTFOUNDEXCEPTION or cannot read the property files.
    The main problem is ...I donot have the complete source code. while decompiling i m not able view complete source code.
    Please help me regarding this.........
    Thanks in advance.

  • Getting error "Cannot read property 'tooltip' of undefined"

    Hi,
    I have Predictive Analysis 1.18. In preferences I have checked Esri ArcGIS online and Entered credentials.
    Also I have reopened the document. But not able to create Geo Map. Getting error as "Cannot read property 'tooltip' of undefined".
    I have attached the screenshot of the same.
    Can anyone please provide the solution?
    Thanks and Regards,
    Bhagyashri

    The new runtime has an internal variable called 'data' in the Symbol class. The code in this composition is also using .data to store some user values which is modifying the internal state of the symbol in runtime and is resulting into js errors. If you change the variable name from data to say _data, this should work. I have already done that in the actions.js file and am attaching the updated copy here. Please do a double check once, as it is used in many places and I might have missed something as I do not understand the domain logic in this code much.
    -Dharmendra

  • Loading properies file from JSP

    Hi All,
    I am storing both the jsp file and properties file in the same folder. I am using tomcat web container. When I load the JSP into a browser, I am getting file not found exception. Can you please tell me how to resolve this problem. Very urgent.
    Following is the code line I used.
    FileInputStream in= new FileInputStream("currentDate.properties");
    Thanks,
    ---Nagesh

    you can follow this also.
    if ur jsp name is myjsp.jsp then the java file will be myjsp_jsp rite.
    ur property file will be under the classes folder.
    public Properties getProperty(String filename)
              InputStream is = null;
              Properties props = new Properties();       
              ClassLoader classLoader = myjsp_jsp.class.getClassLoader();      
              is = classLoader.getResourceAsStream(filename);
              if(is == null)
                  String message = "Cannot locate property file " + filename + " in the classpath";
                  System.out.println(message);               
              try
                  props.load(is);
              catch (IOException e)
                  String message = "Error reading property file " + filename;             
                  System.out.println(message);     
              finally
                  try
                   is.close();
                  catch(Throwable t)
                   t.printStackTrace();
              if(props.isEmpty())
                  String message = "No properties are defined in " + filename;         
                  System.out.println(message);     
         return props;  
         }

  • Upgrade v5.0 Error: Cannot read property 'timeline' of undefined

    Hi, I have this Error Uncaught TypeError: Cannot read property 'timeline' of undefined after upgrade to version 5.0 the older version of project works fine, any idea how to fix it?

    The new runtime has an internal variable called 'data' in the Symbol class. The code in this composition is also using .data to store some user values which is modifying the internal state of the symbol in runtime and is resulting into js errors. If you change the variable name from data to say _data, this should work. I have already done that in the actions.js file and am attaching the updated copy here. Please do a double check once, as it is used in many places and I might have missed something as I do not understand the domain logic in this code much.
    -Dharmendra

  • Edge.4.js Cannot read property 'symbolData' of undefined

    Hi
    Some times when open my project in the browser I get error: Cannot read property 'symbolData' of undefined   ...../edge_includes/edge.4.0.0.min.js:184
    I found a mention similar in the forum Error playing movie on slow connection
    but I have not a slow connection.
    help, some idea how to fix?
    my files are:
    project.html               3 kb
    project_edge.js          669 kb
    project_edgeActions.js    16 kb
    project_edgePreload.js    15 kb
    thanks,
    Paul

    Hi Paul ,
    We figured out that in some cases this issue comes up if you have empty symbols in your project? Can you check and if you have empty symbols can you delete them from the composition?
    If possible, share the composition with us so that we can investigate the issue better?
    Thanks and Regards,
    Sudeshna Sarkar

  • Muse Craziness and Error: Cannot read property 'parent node' of undefined

    I have finished my site and exported as HTML, when you open the index file you see a quick preview of the site then the page goes white.
    If I preview the site in a browser from Muse menu selection, I get this error and the content in my light boxes is all moved and some items not showing. Even pulled my footer items into the light box.
    Note that all of this only happens when previewed or exported as HTML. Everything works as it should in the design mode. When I hit the preview tab, the browser fill shows then Muse is not responsive for 15-25 min.
    I have no "added" Java Scripts, only used the available widgets within muse, I do have widgets nested inside of widgets which I believe may be the problem?
    Error Im getting from the browsers (all of them)
    "MuseJSAssert: Error calling selector function:TypeError: Cannot read property 'parent node' of undefined"
    I have began building my site in DW as this is becoming the usuall trip with Muse, as in every tiny change creates a ton of problems after export. The initial release was great and after the first update things just seem to be going downhill with every new update.

    Hi JKurtBrown,
    You seem to have some invalid HTML in a few of your custom HTML fields that is causing issues with the rest of the page. In many of the places where you have tables, you seem to have copy/pasted from a different source, but you are missing closing </div> tags for some of your code. Cleaning these up and closing these divs should allow your page to work without issue. If you need help narrowing down where the issues are, you can use the W3C Validator and it should be able to tell you where your issues are. The ones that say "No Closing Tag" are the ones you'll want to go through and fix first, as often times those can cause a lot of other issues.
    Hope that helps,
    Andrew

  • JSP to Upload file from client machine to Web Server!

    Hi,
    I want to upload a file from client machine to web server in order to send it as email attachment, How can I do it? After uploading the file the class should give me the path where the file is stored on the web server and the file name in return!
    I know the HTML <file> field but dont know how to copy it on web server, HTML Part will be:
    <FORM ENCTYPE="multipart/form-data"
    method="POST" action="My.jsp">
    <INPUT TYPE="file" NAME="mptest">
    <INPUT TYPE="submit" VALUE="upload">
    </FORM>
    Please help!
    Thanks,
    - Rahul

    You can use cos.jar provided by O'Reilly from http://www.servlets.com/cos/. Take a look at com.oreilly.servlet.multipart.* classes.
    Package is provided with source, classes, documentation and, of course, ready-to-use jar file.
    It is really usefull and - ready!

Maybe you are looking for