⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessiontool.java

📁 企业进销存源码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -