This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Getting my JSP properties file - please hel  RSS feed

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
Please spare some of your precious time to help me with this. I think it might be a basic Java problem but maybe a JSP/servlet problem too. Here is what I'm trying to do:
I have a jsp which runs off the Tomcat root context in my home machine as follows E:\Tomcat33\webapps\ROOT\mysite\myjsp.jsp
I then want to know the current directory where this jsp is running. I use application.getRealPath(request.getServletPath()) and I get it as: E:\Tomcat33\webapps\ROOT\mysite\myjsp.jsp
I then want to load a properties file using the above location which means that I want the path : E:\Tomcat33\webapps\ROOT\mysite\myprop.properties
I'm using this technique to avoid hardcoding.
How could I then manipulate: E:\Tomcat33\webapps\ROOT\mysite\myjsp.jsp into E:\Tomcat33\webapps\ROOT\mysite\myprop.properties? I have looked at the String class but none of the methods there seem to help me.
Your help would be greatly appreciated.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use random access file for property file.Get the path and store it in string append that string to file.
------------------
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How could I then manipulate:
E:\Tomcat33\webapps\ROOT\mysite\myjsp.jsp into
E:\Tomcat33\webapps\ROOT\mysite\myprop.properties
1. Use the String method
int p = lastIndexOf( '\\' ) to find the last separator.
2. Add the file name
String pth = jspPath.substring(0,p ) + "\\myprop.properties" ;
That really should be File.separatorChar instead of '\\'
Bill

------------------
author of:
 
ernest fakudze
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, thank you very very much for your help guys! Now I can have good nights since this thing is done. Really appreciate.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!