当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletRequest.getServerName方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getServerName方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getServerName方法的具体用法?Java HttpServletRequest.getServerName怎么用?Java HttpServletRequest.getServerName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getServerName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBasePath

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 获取请求basePath
 * @param request
 * @return
 */
public static String getBasePath(HttpServletRequest request) {
	StringBuffer basePath = new StringBuffer();
	String scheme = request.getScheme();
	String domain = request.getServerName();
	int port = request.getServerPort();
	basePath.append(scheme);
	basePath.append("://");
	basePath.append(domain);
	if("http".equalsIgnoreCase(scheme) && 80 != port) {
		basePath.append(":").append(String.valueOf(port));
	} else if("https".equalsIgnoreCase(scheme) && port != 443) {
		basePath.append(":").append(String.valueOf(port));
	}
	return basePath.toString();
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:21,代码来源:RequestUtil.java

示例2: getWebRoot

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 得到项目根路径(形如: http://bridgeli.cn/)
 * 
 * @param request
 * @return
 */
public static String getWebRoot(HttpServletRequest request) {
    // 得到协议如:http
    String scheme = request.getScheme();
    // 得到服务器名称如:127.0.0.1
    String serverName = request.getServerName();
    // 得到端口号如8080
    int serverPort = request.getServerPort();
    // 得到当前上下文路径,也就是安装后的文件夹位置。
    String contextPath = request.getContextPath();
    // 连起来拼成完整的url
    StringBuffer sb = new StringBuffer();
    sb.append(scheme);
    sb.append("://");
    sb.append(serverName);
    if (80 != serverPort) {
        sb.append(":");
        sb.append(serverPort);
    }
    sb.append(contextPath);
    sb.append("/");
    return sb.toString();
}
 
开发者ID:bridgeli,项目名称:netty-socketio-demo,代码行数:29,代码来源:WebUtils.java

示例3: redirect

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private boolean redirect(HttpServletRequest request, HttpServletResponse response){
        String url = "http://" + request.getServerName() + ":"
                + request.getServerPort() + request.getContextPath();
        try {
//            request.getSession().setAttribute("redirect",request.getServletPath());
            response.sendRedirect(url);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
 
开发者ID:tomoncle,项目名称:JavaStudy,代码行数:13,代码来源:AuthInterceptorAdapter.java

示例4: getServerBaseUrl

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getServerBaseUrl(final HttpServletRequest request){
    String schema=request.getHeader("x-forwarded-proto");
    if(schema==null || "".equals(schema)){
        schema=request.getScheme();
    }
    schema+="://";
    String host =request.getHeader("x-forwarded-host");
    if(host==null || "".equals(host)){
        host=request.getServerName() + ":" + request.getServerPort();
    }
    String url=schema+host;
    url=regularUrl(url);

    return url;
}
 
开发者ID:bingo-oss,项目名称:sso-client,代码行数:16,代码来源:Urls.java

示例5: getUrlBase

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getUrlBase(HttpServletRequest request) {
  if ((request.getServerPort() == 80) || (request.getServerPort() == 443)) {
    return request.getScheme() + "://" + request.getServerName();
  } else {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:8,代码来源:HttpUtil.java

示例6: getFullURL

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 获取Http请求的完整路径,包括参数
 *
 * @param request
 * @return
 */
public static String getFullURL(HttpServletRequest request) {
	String url = "";
	url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getServletPath();
	if (request.getQueryString() != null) {
		url += "?" + request.getQueryString();
	}
	return url;
}
 
开发者ID:funtl,项目名称:framework,代码行数:15,代码来源:RequestUtils.java

示例7: isLocalOrigin

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private boolean isLocalOrigin(HttpServletRequest request, String origin) {

        // Build scheme://host:port from request
        StringBuilder target = new StringBuilder();
        String scheme = request.getScheme();
        if (scheme == null) {
            return false;
        } else {
            scheme = scheme.toLowerCase(Locale.ENGLISH);
        }
        target.append(scheme);
        target.append("://");

        String host = request.getServerName();
        if (host == null) {
            return false;
        }
        target.append(host);

        int port = request.getServerPort();
        if ("http".equals(scheme) && port != 80 ||
                "https".equals(scheme) && port != 443) {
            target.append(':');
            target.append(port);
        }

        return origin.equalsIgnoreCase(target.toString());
    }
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:29,代码来源:CorsFilter.java

示例8: processRequest

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	response.setContentType("text/html;charset=UTF-8");
	try (PrintWriter out = response.getWriter()) {
		out.println("<html>");
		out.println("<head>");
		out.println("<title>Invoke the servlet clients</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>Invoke the servlet clients</h1>");

		String path = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()
				+ "/WritingServlet";
		out.println("Invoking the endpoint: " + path + "<br>");
		out.flush();
		URL url = new URL(path);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		try (BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
			out.println("Sending data ..." + "<br>");
			out.flush();
			out.println(input.readLine());
			out.println("Sleeping ..." + "<br>");
			out.flush();
			sleep(5000);
			out.println("Sending more data ..." + "<br>");
			out.flush();
			out.println(input.readLine());
			input.close();
		}
		out.println("<br><br>Check server.log for output");
		out.println("</body>");
		out.println("</html>");
	} catch (InterruptedException | IOException ex) {
		logger.log(SEVERE, null, ex);
	}
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:37,代码来源:ReadClient.java

示例9: doGet

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
  String redirectUrl = request.getScheme() + "://"
    + request.getServerName() + ":" + regionServerInfoPort
    + request.getRequestURI();
  response.sendRedirect(redirectUrl);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:9,代码来源:HMaster.java

示例10: getApplicationRootUrl

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getApplicationRootUrl() {
	try {
		HttpServletRequest request = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
		URL reconstructedUrl = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "");
		return reconstructedUrl.toString();
	} catch (Exception e) {
		return getHttpBaseUrl();
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:10,代码来源:WebUtil.java

示例11: execute

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public String execute() throws Exception {
	HttpServletRequest request=Struts2Utils.getRequest();
	String tabId=request.getParameter("tabId");

	String baseUrl = "";
	baseUrl = request.getScheme() +"://" + request.getServerName()  
					+ (request.getServerPort() == 80 ? "" : ":" +request.getServerPort())
                       + request.getContextPath();

	request.setAttribute("baseUrl", baseUrl);

	User user=accountManager.getCurUser();
   	if(user!=null){
   		SurveyDirectory surveyDirectory=surveyDirectoryManager.getSurveyByUser(surveyId, user.getId());
   		if(surveyDirectory!=null){
   			request.setAttribute("survey", surveyDirectory);
   			if(IFRAME.equals(tabId)){
   				return IFRAME;
   			}else if(SITECOMP.equals(tabId)){
   				return SITECOMP;
   			}else if(WEIXIN.equals(tabId)){
   				return WEIXIN;
   			}else if(SHARE.equals(tabId)){
   				return SHARE;
   			}
   			return COLLECT1;
   		}
   	}
	return null;
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:32,代码来源:MyCollectAction.java

示例12: doFilterInternal

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
	String requestURI = request.getRequestURI();
	LOG.debug("filt uri : " + requestURI);
	
	requestURI = requestURI.replaceAll("/+", "/");
	if (requestURI.equals("/")||requestURI.startsWith("/resources")|| requestURI.equals("/home/auth")) {
		filterChain.doFilter(request, response);
		return;
	}
	String path = request.getContextPath();
	this.basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	
	HttpSession session = request.getSession();
	
	User user=(User) session.getAttribute("curUser");
	if(null==user){
		java.io.PrintWriter out = response.getWriter();
	    out.println("<html>");
	    out.println("<script>");
	    out.println("window.open ('"+basePath+"','_top')");
	    out.println("</script>");
	    out.println("</html>");
	}else{
		filterChain.doFilter(request, response);
		return;
	}
}
 
开发者ID:elves-project,项目名称:supervisor,代码行数:29,代码来源:LoginFilter.java

示例13: assembleCallbackUrl

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected String assembleCallbackUrl(HttpServletRequest request) {
    return request.getScheme() + "://" +
            request.getServerName() +
            getServerPort(request) +
            request.getContextPath();

}
 
开发者ID:atbashEE,项目名称:jsr375-extensions,代码行数:8,代码来源:OAuth2ServiceFactory.java

示例14: authenticate

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Authenticate the user making this request, based on the specified
 * login configuration.  Return <code>true</code> if any specified
 * constraint has been satisfied, or <code>false</code> if we have
 * created a response challenge already.
 *
 * @param request Request we are processing
 * @param response Response we are creating
 * @param login Login configuration describing how authentication
 *              should be performed
 *
 * @exception IOException if an input/output error occurs
 */
public boolean authenticate(HttpRequest request,
                            HttpResponse response,
                            LoginConfig config)
    throws IOException {

    // Have we already authenticated someone?
    Principal principal =
        ((HttpServletRequest) request.getRequest()).getUserPrincipal();
    if (principal != null) {
        if (debug >= 1)
            log("Already authenticated '" + principal.getName() + "'");
        return (true);
    }

    // Validate any credentials already included with this request
    HttpServletRequest hreq =
        (HttpServletRequest) request.getRequest();
    HttpServletResponse hres =
        (HttpServletResponse) response.getResponse();
    String authorization = request.getAuthorization();
    String username = parseUsername(authorization);
    String password = parsePassword(authorization);
    principal = context.getRealm().authenticate(username, password);
    if (principal != null) {
        register(request, response, principal, Constants.BASIC_METHOD,
                 username, password);
        return (true);
    }

    // Send an "unauthorized" response and an appropriate challenge
    String realmName = config.getRealmName();
    if (realmName == null)
        realmName = hreq.getServerName() + ":" + hreq.getServerPort();
//        if (debug >= 1)
//            log("Challenging for realm '" + realmName + "'");
    hres.setHeader("WWW-Authenticate",
                   "Basic realm=\"" + realmName + "\"");
    hres.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    //      hres.flushBuffer();
    return (false);

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:56,代码来源:BasicAuthenticator.java

示例15: setAuthenticateHeader

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Generates the WWW-Authenticate header.
 * <p>
 * The header MUST follow this template :
 * <pre>
 *      WWW-Authenticate    = "WWW-Authenticate" ":" "Digest"
 *                            digest-challenge
 *
 *      digest-challenge    = 1#( realm | [ domain ] | nOnce |
 *                  [ digest-opaque ] |[ stale ] | [ algorithm ] )
 *
 *      realm               = "realm" "=" realm-value
 *      realm-value         = quoted-string
 *      domain              = "domain" "=" <"> 1#URI <">
 *      nonce               = "nonce" "=" nonce-value
 *      nonce-value         = quoted-string
 *      opaque              = "opaque" "=" quoted-string
 *      stale               = "stale" "=" ( "true" | "false" )
 *      algorithm           = "algorithm" "=" ( "MD5" | token )
 * </pre>
 *
 * @param request HTTP Servlet request
 * @param resonse HTTP Servlet response
 * @param login Login configuration describing how authentication
 *              should be performed
 * @param nOnce nonce token
 */
protected void setAuthenticateHeader(HttpServletRequest request,
                                     HttpServletResponse response,
                                     LoginConfig config,
                                     String nOnce) {

    // Get the realm name
    String realmName = config.getRealmName();
    if (realmName == null)
        realmName = request.getServerName() + ":"
            + request.getServerPort();

    byte[] buffer = md5Helper.digest(nOnce.getBytes());

    String authenticateHeader = "Digest realm=\"" + realmName + "\", "
        +  "qop=\"auth\", nonce=\"" + nOnce + "\", " + "opaque=\""
        + md5Encoder.encode(buffer) + "\"";
    // System.out.println("Authenticate header value : "
    //                   + authenticateHeader);
    response.setHeader("WWW-Authenticate", authenticateHeader);

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:49,代码来源:DigestAuthenticator.java


注:本文中的javax.servlet.http.HttpServletRequest.getServerName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。