gwt getting abosulte path on server side

£可爱£侵袭症+ 提交于 2019-12-13 08:02:06

问题


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


回答1:


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:




回答2:


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.



来源:https://stackoverflow.com/questions/23475589/gwt-getting-abosulte-path-on-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!