This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem about path in JSP and Bean  RSS feed

 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

my web application contain jsp and support class(Bean).

in jsp i use BeanClass,
in BeanClass, some function read file content just like new File("/resource/file1.txt");
i put BeanClass.class in /WEB-INF/classes folder and jsp file under application context(/).

when i call BeanClass's function from jsp FileNotFound Exception occurs and it search file under %tomcat_directory%\webapps\resource\file1.txt even though i expected the path will be /my_context/resource/file1.txt


I'd like to know that how to point path relatively in BeanClass. I dont want to pass realPath from jsp to the bean. how can Bean will point dependently to the certain file location.


thanks,
kaze
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try getResourceAsStream(String path) method in ServletContext rather than using new File().

The path expected by this method is the relative path, so /resource/<filename> should work fine.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kami Kaze"

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sravan Kumar,

Thanks for your reply.

Kami Kaze
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kami Kaze", My request that you change your display name to adhere to JavaRanch standards was not a suggestion. Valid display names are mandatory for participation on the Ranch. Please change your display name as instructed prior to your next post.

Be aware that accounts with invalid display names are removed.

bear
JavaRanch Sheriff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!