Solved

path problem

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 171
SHA2 certs for IIS AND Java? 2 113
how to see all occupied ports on windows 10 laptop 15 76
by zero exception 10 52
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

856 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