Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
TB源码分析:LoginManager

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

package com.terac.board;

import com.terac.util.CookieUtil;
import com.terac.util.StringUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class LoginManager {

public static void login(HttpServletResponse response, int id, String userName, int cookieMaxAge) {
CookieUtil.setCookie(response, "userId", String.valueOf(id), cookieMaxAge);
try {
CookieUtil.setCookie(response, "userName", URLEncoder.encode(userName, "UTF-8"), cookieMaxAge);
} catch (UnsupportedEncodingException e) {
//
}
}

public static boolean isLogined(HttpServletRequest request) {
boolean result = false;
if (getUserId(request) > 0) {
result = true;
}
return result;
}

public static int getUserId(HttpServletRequest request) {
int userId = StringUtil.parseInt(CookieUtil.getString(request, "userId"));
return userId;
}

public static String getUserName(HttpServletRequest request) {
String userName = null;
try {
userName = URLDecoder.decode(CookieUtil.getString(request, "userName"), "UTF-8");
} catch (UnsupportedEncodingException e) {
//
}
return userName;
}

public static void logout(HttpServletResponse response) {
CookieUtil.setCookie(response, "userId", "", -1);
CookieUtil.setCookie(response, "userName", "", -1);
}


}




相关文章

相关软件