完整的获取当前jsp文件路径的语句

错误:
String realPath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
String realPath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getServletPath();
正确:
String realPath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()+request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1);

你可能感兴趣的:(jsp,String)