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

📄 checklogin.java

📁 Java2程序设计150例德源代码
💻 JAVA
字号:
//checkLogin.java
package beans;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class checkLogin {
	public String username = "";

	public boolean check(HttpServletRequest req, HttpServletResponse res)
		throws IOException, ServletException {
		String cookieName = "username";
		PrintWriter out = res.getWriter();
		try {
			Cookie[] myCookies = req.getCookies();
			this.username =
				this.getCookieValue(myCookies, cookieName, "not found");
		} 
		catch (Exception e) {
			return false;
		}

		if (!this.username.equals(new String("not found"))) {
			return true;
		} 
		else {
			return false;
		}

	}

	public String getUserName() {
		return this.username;
	}

	public static String getCookieValue(
		Cookie[] cookies,
		String cookieName,
		String defaultValue) {
		for (int i = 0; i < cookies.length; i++) {
			Cookie cookie = cookies[i];
			if (cookieName.equals(cookie.getName()))
				return (cookie.getValue());
		}
		return (defaultValue);
	}
}

⌨️ 快捷键说明

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