Frage

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

War es hilfreich?

Lösung

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top