问题
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