jsp 获取完整url 带参数或不带参数

    <%
		String url=request.getScheme()+"://"; 
		url+=request.getHeader("host"); 
		url+=request.getRequestURI(); 
		if(request.getQueryString()!=null) 
		url+="?"+request.getQueryString(); 
		out.println(url);

    %>
<%
 	String  realPath1  =  "http://"  +  request.getServerName()  +  ":"  +  request.getServerPort()  +  request.getContextPath()+request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1);  
 	String  realPath2  =  "http://"  +  request.getServerName()  +  ":"  +  request.getServerPort()  +  request.getContextPath()+request.getServletPath();
    out.println("web  URL  路径1:"+realPath1);
    out.println("web  URL  路径2:"+realPath2);
%>

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