• 在Web.xml中定义自己的过滤器


    1.过滤器代码

     1 package com.zkj.filter;
     2 
     3 import java.io.IOException;
     4 import java.io.PrintWriter;
     5 
     6 import javax.servlet.Filter;
     7 import javax.servlet.FilterChain;
     8 import javax.servlet.FilterConfig;
     9 import javax.servlet.ServletException;
    10 import javax.servlet.ServletRequest;
    11 import javax.servlet.ServletResponse;
    12 import javax.servlet.http.HttpServlet;
    13 import javax.servlet.http.HttpServletRequest;
    14 import javax.servlet.http.HttpServletResponse;
    15 
    16 public class MyFilter extends HttpServlet implements Filter {
    17 
    18     public void doFilter(ServletRequest arg0, ServletResponse arg1,
    19             FilterChain arg2) throws IOException, ServletException {
    20         // TODO Auto-generated method stub
    21         arg0.setCharacterEncoding("utf-8");
    22         arg2.doFilter(arg0, arg1);
    23     }
    24 
    25     public void init(FilterConfig arg0) throws ServletException {
    26         // TODO Auto-generated method stub
    27         
    28     }
    29 
    30 }
    中文处理

    2.web.xml配置

    <!--配置自己的过滤器-->
      <filter>
          <filter-name>MyFilter</filter-name>
          <filter-class>com.zkj.filter.MyFilter</filter-class>
      </filter>
      <filter-mapping>
          <filter-name>MyFilter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>

    3.jsp文件放入WEB-INF目录巧处理之index.jsp代码

    <body>
        <jsp:forward page="WEB-INF/register.jsp"></jsp:forward>
      </body>
  • 相关阅读:
    8.18 二讲背包问题之完全背包
    8.18 动态规划——背包问题之01背包
    8.17 动态规划——书的抄写
    7.25 二分查找模板
    7.19 股票问题
    7.12 枚举-Jam的计数法
    7.12 递归——双色hanoi塔问题
    7.11 NOIP2007普及组第3题 守望者的逃离
    高数之泰勒公式
    数据结构_线性表之链表(1)
  • 原文地址:https://www.cnblogs.com/jiqiwoniu/p/4455820.html
Copyright © 2020-2023  润新知