Solved

path problem

Posted on 2002-05-02
5
248 Views
Last Modified: 2010-03-31
Here is my first jsp page for translating xml against xsl.
The path should be changed if I copy it to another machine, like c:\root\result.xml.
How can I the the actual path and I don't care the path before the file name?

Thanks.

<%@ page
     import=     "java.io.*,
               org.w3c.dom.*,
               javax.xml.transform.*,
               javax.xml.transform.stream.*,
               java.io.*"
%>
<%

     StreamSource xml = new StreamSource(new File("C:/java/jakarta-tomcat-4.0.3/webapps/ROOT/test/result.xml"));
     StreamSource xsl = new StreamSource(new File("C:/java/jakarta-tomcat-4.0.3/webapps/ROOT/test/result.xsl"));
     
     StreamResult result = new StreamResult(out);
     
     TransformerFactory tFactory = TransformerFactory.newInstance();
     Transformer transformer = tFactory.newTransformer(xsl);

     transformer.transform(xml, result);
     
%>
0
Comment
Question by:iamjhkang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 6988103
 Well you certainly cannot change it if you hard code it. At least not without recompiling. WhatI would suggest is to read the path from a configuration file. Doing it this way you only have to change the configuration file and not the source code. Using resourceBundler is a very good idea.

  If you do not want to have a configuration file you can always read the path using the System class through the "System.getProperty("<property here>");" piece of code (like System.getProperty("java.class.path") for example).

  Hope it helps.
0
 
LVL 1

Expert Comment

by:naveeth
ID: 6988296
yah you can do as said by girionis
the code looks some what like this
first step is to keep the property file in known directory say java home
then
read the path of property file
<%
String path = System.getProperty("java.home");


    StreamSource xml = new StreamSource(new File(path+"/result.xml"));
    StreamSource xsl = new StreamSource(new File(path+"/result.xsl"));
   
   

0
 
LVL 1

Author Comment

by:iamjhkang
ID: 6992523
System.getProperty("java.home") equals c:\java\j2sdk1.4.0\jre not the home of web server.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7992970
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts refunded
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8048430
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question