Solved

path problem

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 82
Java Options in Zimbra Server 2 50
print map entry 34 67
arguments to jar 5 26
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

786 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