最好是把代码写出来,急用,谢谢~~
------解决方案--------------------
过滤器主要用于,判断用户是否登陆,以防止接访问应用中的网页进行提交。
参考代码
- Java code
package filter;import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.*;import com.tarena.crm.domain.admin.Manager;public class LoginFilter extends HttpServlet implements Filter{ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req=(HttpServletRequest)request; HttpServletResponse res=(HttpServletResponse) response; if(req.getSession().getAttribute("manager")==null){ res.sendRedirect("/crm/core/login.jsp"); }else chain.doFilter(request, response); } public void init(FilterConfig arg0) throws ServletException { }}
------解决方案--------------------
不会过滤器的话就用JSP代码写吧。
首先你在用户登录以后把用户的ID写到session里。
session.setAttribute("userid",userid);后边的userid是变量;
然后建一个safe.jsp,代码如下
- HTML code
<% if(session.getAttribute("userid")==null){%> <script> alert("SORRY,LOGIN PLEASE!"); window.location.href="login.jsp";<!--这里是你的登录页面 --> </script> <%}%>