懒羊羊
2024-01-31 e57a8990ae56f657a59c435a0613c5f7a8728003
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.jcdm.framework.config;
 
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;
import com.jcdm.common.utils.ServletUtils;
 
/**
 * 服务相关配置
 * 
 * @author jc
 */
@Component
public class ServerConfig
{
    /**
     * 获取完整的请求路径,包括:域名,端口,上下文访问路径
     * 
     * @return 服务地址
     */
    public String getUrl()
    {
        HttpServletRequest request = ServletUtils.getRequest();
        return getDomain(request);
    }
 
    public static String getDomain(HttpServletRequest request)
    {
        StringBuffer url = request.getRequestURL();
        String contextPath = request.getServletContext().getContextPath();
        return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString();
    }
}