?
Solved

path problem

Posted on 2002-05-02
5
Medium Priority
?
250 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

800 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