Question

Iam trying since 1 hour to get the absolute path of a file ony server side:

   String path =  request.getRequestURL();

JasperCompileManager.compileReportToFile(path+"/test.jrxml",path+"/test.jasper");

this didnt work my expection is :

not found : http\12.0.0.13:8080]\test\test.jrxml wrong syntax in dataname...etc

Was it helpful?

Solution

Try this one in your RemoteServiceServlet class to get the absolute path of any resources placed under war directory that will be actually the path of server directory when deployed on server.

String pngFullPath = this.getThreadLocalRequest().getSession().getServletContext()
        .getRealPath("images/1.png");
System.out.println(pngFullPath);


String icoFullPath = this.getThreadLocalRequest().getSession().getServletContext()
        .getRealPath("favicon.ico");
System.out.println(icoFullPath);

output:

D:\Workspace\GWTProject\war\images\1.png
D:\Workspace\GWTProject\war\favicon.ico

Now change it as per the placement of test.jrxml file in your project.

here is the project structure:

enter image description here

OTHER TIPS

This is the method I use:

public static String getServerBase(HttpServletRequest req)
{
    String scheme = req.getScheme(); // http
    String serverName = req.getServerName(); // sub.domain.ac.uk
    int serverPort = req.getServerPort(); // 80
    String contextPath = req.getContextPath(); // /MyApp

    return scheme + "://" + serverName + ":" + serverPort + contextPath;
}

Then simply append your file name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top