在jsp中写了如下代码:
<%
String path1=request.getScheme();
String path2=request.getServerName();
int path3=request.getServerPort();
String path4=request.getContextPath();
System.out.println(path1);
System.out.println(path2);
System.out.println(path3);
System.out.println(path4);
System.out.println("----------");
%>
控制台输出如下:
http
localhost
8080
/pro_1000_war_exploded
----------
即在项目中可使用如下拼凑的链接
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
网友评论