sessiontool.java

来自「企业进销存源码」· Java 代码 · 共 63 行

JAVA
63
字号
package com.web.util;

import javax.servlet.http.*;

/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class SessionTool {
    public static String getNameByRequest(HttpServletRequest request) {
        String sessionName = "";

        sessionName = request.getServletPath();
        sessionName = sessionName.replace('.', '_');
        sessionName = sessionName.replace('/', '_');

        return sessionName;
    }

    public static String getPathByRequest(
            HttpServletRequest request,
            String path) {
        String contextPath = request.getContextPath();
        String newPath = "";

        if (!contextPath.equals("/")) {
            newPath = contextPath + path;
        } else {
            newPath = path;
        }

        return newPath;
    }

    public static String getServerRoot(HttpServletRequest request) {
        StringBuffer buffer = new StringBuffer();

        buffer.append("http://");
        buffer.append(request.getServerName());
        buffer.append(":" + request.getServerPort());

        if (!request.getContextPath().equals("/")) {
            buffer.append(request.getContextPath());
        }

        return buffer.toString();
    }

    public static String getRootName(HttpServletRequest request){
        String contextPath = request.getContextPath();

        if(contextPath.equals("/")){
              contextPath="";
        }

        return contextPath;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?