FileNotFoundException when accessing a file from JSP but works if accessed from plain java application

anirudh

I am trying to access a properties file from java and it works file when I run it as a stand-alone java application. But, when I call the method accessing the file from a jsp page running on a tomcat server, I get a FileNotFoundException.

I think that when the files are deployed into a server, their path changes, and thats why the exception occurs from a web-app but not directly in java. Below is the project explorer view of my project.

enter image description here

I am accessing the nWMS properties file from the LabelRequestMessages class in java. Below is the code with which I access the file in java.

in = new FileInputStream("resources-dev/com/infosys/gidl2/shiplabel/mybatis/config/"
                            + propsDB); //propsDB has the file name
            props.load(in);

Could someone please tell me how to provide the path so that the file is accessible when deployed in a tomcat server.

RMachnik

You are trying to get resources inside your .war application please consider using that

private static final String ENDINGS_FILE_NAME = "com/infosys/gidl2/shiplabel/mybatis/config/" + propsDB;
...
InputStream is = getClass( ).getResourceAsStream(ENDINGS_FILE_NAME); 

But first remember to set resources folder in your web.xml, because tomcat needs to know where search it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Accessing linux local file system from java web application

From Dev

Accessing linux local file system from java web application

From Dev

Accessing java variable from javascript on same jsp

From Dev

Throws FileNotFoundException when creating scanner from file

From Dev

Kotlin object private when accessed from Java

From Dev

Accessing java fx clipboard from a commandline application?

From Dev

Accessing Office 365 cloud from Java Application

From Dev

Accessing bitsy using gremlin from a java application

From Dev

Accessing remote java file (.jar) from php

From Dev

Accessing properties in Karaf cfg file from java?

From Dev

Accessing properties in Karaf cfg file from java?

From Dev

FileNotFoundException when opening wav file from android assets

From Dev

FileNotFoundException(permission) when trying to write string from web to file

From Dev

create java function in a jsp file and call it from another jsp file

From Dev

create java function in a jsp file and call it from another jsp file

From Dev

FileNotFoundException- Copying a file from my local to server using java

From Dev

Get the filename of the file from FileNotFoundException

From Dev

Get the filename of the file from FileNotFoundException

From Dev

Scala public becomes private when accessed from Java?

From Dev

FileNotFoundException when loading API from URL. Java. Android

From Dev

java.io.FileNotFoundException while accessing from S3 bucket?

From Dev

Glade - Invalid object type 'WebKitWebView' when loading from file. works on Glade Application

From Dev

Access denied when opening WMV file from Java application

From Dev

Access denied when opening WMV file from Java application

From Dev

Accessing File from ClassPath

From Dev

Accessing data from file

From Dev

Getting IllegalStateException: No such servlet: jsp when accessing deployed java application to Google App Engine

From Dev

Java local variable accessed from within inner class; needs to be declared final, why it works in NetBeans?

From Dev

Accessing an Instance of an Object from a Serlvet in Java Web Application

Related Related

  1. 1

    Accessing linux local file system from java web application

  2. 2

    Accessing linux local file system from java web application

  3. 3

    Accessing java variable from javascript on same jsp

  4. 4

    Throws FileNotFoundException when creating scanner from file

  5. 5

    Kotlin object private when accessed from Java

  6. 6

    Accessing java fx clipboard from a commandline application?

  7. 7

    Accessing Office 365 cloud from Java Application

  8. 8

    Accessing bitsy using gremlin from a java application

  9. 9

    Accessing remote java file (.jar) from php

  10. 10

    Accessing properties in Karaf cfg file from java?

  11. 11

    Accessing properties in Karaf cfg file from java?

  12. 12

    FileNotFoundException when opening wav file from android assets

  13. 13

    FileNotFoundException(permission) when trying to write string from web to file

  14. 14

    create java function in a jsp file and call it from another jsp file

  15. 15

    create java function in a jsp file and call it from another jsp file

  16. 16

    FileNotFoundException- Copying a file from my local to server using java

  17. 17

    Get the filename of the file from FileNotFoundException

  18. 18

    Get the filename of the file from FileNotFoundException

  19. 19

    Scala public becomes private when accessed from Java?

  20. 20

    FileNotFoundException when loading API from URL. Java. Android

  21. 21

    java.io.FileNotFoundException while accessing from S3 bucket?

  22. 22

    Glade - Invalid object type 'WebKitWebView' when loading from file. works on Glade Application

  23. 23

    Access denied when opening WMV file from Java application

  24. 24

    Access denied when opening WMV file from Java application

  25. 25

    Accessing File from ClassPath

  26. 26

    Accessing data from file

  27. 27

    Getting IllegalStateException: No such servlet: jsp when accessing deployed java application to Google App Engine

  28. 28

    Java local variable accessed from within inner class; needs to be declared final, why it works in NetBeans?

  29. 29

    Accessing an Instance of an Object from a Serlvet in Java Web Application

HotTag

Archive