getServletContext().getRealPath("/")的测试

Java代码在/Obatv/src/com/obatv/sys/web/controller/UserControl.java

关键代码:

	
        @ResponseBody
	@RequestMapping(value = "/test1.do")
	public String testPath1(HttpServletRequest req){
		String pathString = CommonInfo.realDir + CommonInfo.productImageRealDir;
		String curr = req.getServletContext().getRealPath("/");
		return pathString+"======"+curr;
	}
	
	@ResponseBody
	@RequestMapping(value = "222/test2.do")
	public String testPath2(HttpServletRequest req){
		String pathString = CommonInfo.realDir + CommonInfo.productImageRealDir;
		String curr = req.getServletContext().getRealPath("/");
		return pathString+"======"+curr;
	}


实际执行效果 一样。

getServletContext().getRealPath("/")的测试_第1张图片

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的:(servletContext)