I have seen various posts about this but nothing definative about the solution. 
Here's the problem:

I am building a web application to deploy and have no idea whether the 
deployment site runs with Unix or Windows or which Servlet engine they use. In 
theory, this should not be a problem if I deploy the app as a web application 
with no hard-coded paths.

This works well upto a point. My servlet does an XML transformation using an 
XML file and an XSL file. Next, the output is sent to FOP for rendering. 
Unfortunately, the images do not appear.

The images (and xml/xsl files) are currently all stored in the 
web_app_root/WEB-INF directory. I can reference the xml/xsl files without 
hard-coding paths (see code below) but what about the images?

Does anyone know how to do this? My xml file has a graphic like this:

<HTRelitiveRef HTRRKey="2" HTRRType="Picture" HTRRID="centurion.jpg" 
HTRRLink="" HTRRVisible="F">centurion</HTRelitiveRef>

Thanks for your help,


import javax.servlet.http.*;
import javax.servlet.*;
import org.xml.sax.InputSource;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXResult;
import java.io.*;
import java.util.*;
import org.apache.fop.apps.Driver;

public class FopServlet extends HttpServlet {

    public static final String PDF_REQUEST_PARAM = "checklist";

    public void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {

        processRequest(req, res);

    public void doPost(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {

        processRequest(req, res);

    public void processRequest(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {

        ServletContext scntxt = this.getServletContext();
        String pathToFile = scntxt.getRealPath("/WEB-INF");

        File inputXMLFile = new File(pathToFile + "DataFile.xml");
        File inputXSLFile = new File(pathToFile + "PDFTemplate1.xsl");

        java.net.URL test = scntxt.getResource("/centurion.jpg");


        Driver driver = new Driver();

        try {
            Transformer transformer = TransformerFactory.newInstance()
                    .newTransformer(new StreamSource(inputXSLFile));
            transformer.transform(new StreamSource(inputXMLFile), new 
        } catch (TransformerException e) {
        } catch (TransformerFactoryConfigurationError 
transformerFactoryConfigurationError) {



To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to