"java EE Enterprise Application Combat Learning record" Authorityfilter

Source: Internet
Author: User

1  packagesanglp.servlet;2 3 Importjavax.servlet.*;4 Importjavax.servlet.annotation.WebFilter;5 Importjavax.servlet.annotation.WebInitParam;6 Importjavax.servlet.http.HttpServletRequest;7 Importjavax.servlet.http.HttpSession;8 Importjava.io.IOException;9 Ten  one  a /** - * Created by Administrator on 2016/10/5. -  */ the@WebFilter (filtername = "authority", Urlpatterns = {"/*"},initparams = { -@WebInitParam (name = "encoding", value = "UTF-8"), -@WebInitParam (name = "loginpage", value = "/chap2/login.jsp"), -@WebInitParam (name = "prologin", value= "/chap2/prologin.jsp") + }) -  public classAuthorityfilterImplementsFilter { +     //configuration information for accessing the filter a     Privatefilterconfig config; at  - @Override -      public voidInit (filterconfig Filterconfig)throwsservletexception { -          this. config=filterconfig; -     } -  in @Override -      public voidDestroy () { to          this. config=NULL; +     } -  the @Override *      public voidDoFilter (servletrequest servletrequest, servletresponse servletresponse, filterchain Filterchain)throwsioexception, servletexception { $         //gets the configuration parameters for the filterPanax NotoginsengString Encoding=config.getinitparameter ("encoding"); -String Loginpage=config.getinitparameter ("loginpage"); theString Prologin=config.getinitparameter ("prologin"); +         //set the character set for request encoding a servletrequest.setcharacterencoding (encoding); theHttpServletRequest hreq=(httpservletrequest) servletrequest; +HttpSession Session=hreq.getsession (true); -         //get a page for a customer request $String requestpath=Hreq.getservletpath (); $         //if the user of the session range is null, no Dengli is Indicated. And the user requested is neither the login page nor the page that handles the login -         if(session.getattribute ("user") = =NULL&&!requestpath.endswith (loginpage) &&!Requestpath.endswith (PROLOGIN)) { -Servletrequest.setattribute ("tip", "you are not logged in"); the Servletrequest.getrequestdispatcher (loginpage). forward (servletrequest,servletresponse); - Wuyi}Else{ the             //Fulfillment Request - Filterchain.dofilter (servletrequest,servletresponse); wu         } -     } about}

"java EE Enterprise Application Combat Learning record" Authorityfilter

Related Article

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.