我现在用struts1+jasperreports 做报表,可是在应用中老是得不到正确的路径,请大家帮我看一下,谢谢
// 查看考核信息
public ActionForward lookAss(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws JRException {
String path = request.getContextPath();
String string = "C://Program Files//Apache Software Foundation//Tomcat 6.0//webapps//IRSSoftware//ireports//PDF.jrxml";

String paths = System.getProperty("user.dir");
System.out.println(paths);
JasperDesign design = JRXmlLoader.load(string);
return null;
}
 
得到的结果是C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin我怎么样才能得到C://Program Files//Apache Software Foundation//Tomcat 6.0//webapps//IRSSoftware//ireports//PDF.jrxml这个路径呢?

解决方案 »

  1.   

    1.request.getRequestURI() 2.getClass().getResource("/"); 你的需求应该是第二个,试试吧
      

  2.   


    net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: file:\C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%206.0\webapps\IRSSoftware\WEB-INF\classes\ireports\PDF.jasper
    还是报错...晕了,呵呵,祝大家端午节快乐
      

  3.   


    用这个必须注意默认条件下tomcat是会把文件放在它的temp目录下的,可能得不到楼主想要的在webapps下的路径。
      

  4.   

    String rePicPath=paths.replace("/", "\\");
    System.out.println(rePicPath);
      

  5.   

    OK了,感谢各位,把解决的方案写出来.    String path = this.getClass().getResource("/").toString();
        File file=new File(path);
        String partPath=file.getParentFile().getParent().toString()+"\\ireports\\"+fileName;
        String paths=URLDecoder.decode(partPath,"UTF-8").replaceAll("file:\\\\", "");paths就是C://Program Files//Apache Software Foundation//Tomcat 6.0//webapps//IRSSoftware//ireports//PDF.jrxml