Simple application of ajax and how to write filter

一个新手
Release: 2017-09-12 09:33:16
Original
1491 people have browsed it

Simple use of ajax:

function dss(userId,obj){ $.post("test?flag=2",{id:userId},function(data) if("删除成功"==data){ alert("删除成功"); $(obj).parent().parent().remove(); } }); }
Copy after login

filter: Filter in Java is not a standard Servlet. It cannot handle user requests or generate responses to the client. It is mainly used for preprocessing HttpServletRequest and can also be used for postprocessing HttpServletResponse. It is a typical processing chain.
Advantages: The advantage of the filter chain is that it can be interrupted at any time during execution. As long as chain.doFilter() is not executed, subsequent filters and requested content will not be executed. In actual use, special attention must be paid to the execution order of the filter chain.

web.xml configuration filter:
##

 FirstFilter com.jkx.web.filter.FirstFilter  encoding UTF-8    FirstFilter /* 
Copy after login

Write Filter :


package com.jkx.web.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.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class FirstFilter implements Filter{ public String encoding=null; //服务器正常关闭时执行 public void destroy() { System.out.println("FirstFilter销毁"); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; req.setCharacterEncoding(encoding); req.setAttribute("fileParam", "222222"); chain.doFilter(req, resp); } //服务器启动时初始化 public void init(FilterConfig filterConfig) throws ServletException { System.out.println("FirstFilter初始化,被创建"); encoding = filterConfig.getInitParameter("encoding"); } }
Copy after login


The above is the detailed content of Simple application of ajax and how to write filter. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!