利用servlet写的用户注册登陆

源代码在线查看: sessionfilter.java

软件大小: 74 K
上传用户: ybsscauc
关键词: servlet 用户
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.tarena.filter;
				
				import java.io.IOException;
				
				import javax.servlet.FilterChain;
				import javax.servlet.ServletException;
				import javax.servlet.http.HttpServletRequest;
				import javax.servlet.http.HttpServletResponse;
				import javax.servlet.http.HttpSession;
				
				public class SessionFilter extends HttpFilter {
				
					@Override
					public void doFilter(HttpServletRequest request,
							HttpServletResponse response, FilterChain chain)
							throws IOException, ServletException {
						HttpSession session = request.getSession(true);
						String path = request.getServletPath();
						path = path.substring(0, path.indexOf("."));
				
						if (session.getAttribute("userInfo") != null && !path.equals("/login")
								&& !path.equals("/register")) {
							response.sendRedirect("/serv-guides/login.html");
							return;
						} else {
							chain.doFilter(request, response);
						}
					}
				
				}
							

相关资源