通过 request 获取项目路径问题

spring mvc 项目中  , jsp 页面向后台提交一个form 表单, 项目的 实际请求地址为:

http://localhost:8080/bsp/attach/uploadFileKsAttach

后台java 代码:

String uri = request.getRequestURI();//得到的结果为;/bsp/attach/uploadFileKsAttach
String Path =  request.getContextPath();// 得到的结果为 :/bsp 
String uri2 = uri.replace(request.getContextPath(), ""); //得到的结果为 :/attach/uploadFileKsAttach

System.out.println("uri = "+uri+" |__|  Path = "+Path +"  |__| uri2 = "+uri2);
uri = /bsp/attach/uploadFileKsAttach |__|  Path = /bsp  |__| uri2 = /attach/uploadFileKsAttach


你可能感兴趣的:(通过 request 获取项目路径问题)