filter--a URL-level role certification for a directory---learning notes

Source: Internet
Author: User

login.html Login
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
Fiter processing
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.httpservletrequest;import javax.servlet.http.httpservletresponse;//authentication of sensitive catalogs [classroom practice 1]public class FilterDemo7 implements Filter {public void init (Filterconfig filterconfig) throws servletexception {} public void DoFilter (ServletRequest req, servletresponse Res        , Filterchain chain) throws IOException, servletexception {httpservletrequest request = (httpservletrequest) req;        HttpServletResponse response = (httpservletresponse) res;        Set the request Body encoding method request.setcharacterencoding ("UTF-8");        Get user request parameter String username = request.getparameter ("username");        String Password = request.getparameter ("password");        String role = Request.getparameter ("role"); Sentence if (username!=null && password!=null && role!=null && username.trim (). Length () >0 && Password.trim () . Length () >0 && Role.trim (). Length () >0) {if ("Normal user". Equals (role)) {Request.setattrib                Ute ("message", "Welcome to ordinary user <font color= ' blue ' >" +username+ "</font> login");            Request.setattribute ("Flag", "user"); }else if ("Administrator". Equals (role)) {Request.setattribute ("message", "Welcome Administrator <font color= ' red ' >" +username+ "<                 /FONT> Login ");            Request.setattribute ("Flag", "admin");        } chain.dofilter (Request,response); }} public void Destroy () {}}
Results show
<%@ page language="java" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Xml
 <filter>    <filter-name>FilterDemo7</filter-name>    <filter-class>cn.itcast.web.filter.FilterDemo7</filter-class>  </filter>  <filter-mapping>    <filter-name>FilterDemo7</filter-name>    <url-pattern>/welcome.jsp</url-pattern>  </filter-mapping>

filter--a URL-level role certification for a directory---learning notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.