Solved

path problem

Posted on 2002-05-02
5
206 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now