• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp not able to find out txt path  RSS feed

 
yekkala krishna
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i am unable to read txt file from jsp. i am getting null pointer exception.

path of jsp: WEB-INF/views/main.jsp
path of txt: WEB-INF/views/ServerDetails.txt

Following is the code...please suggest where can i make changes to solve the issue.



regards,
rama
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That form of the FileReader constructor looks in the "current directory" - you have NO CONTROL over the current directory in a servlet engine.

Bill
 
yekkala krishna
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,

Thanks for your reply.
In my code if i give full path as shown below its working..


but when i give just ServerDetails.txt its not working.

could you suggest any idea on this?

regards,
rama krishna.y
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, you should be doing this in a Java class, not a JSP.

Secondly, check out ServletContext.getRealPath().
 
yekkala krishna
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Thanks for your suggestion.
Now its working fine.

regards,
Rama Krishna
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!