码迷,mamicode.com
首页 > 其他好文 > 详细

过滤器的使用

时间:2019-04-20 21:44:29      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:click   extends   使用   www   map   dog   extend   pos   xtend   

技术图片

使用过滤器,代码如下:

技术图片
package pers.eddy.hello;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String usr = req.getParameter("usr");
        String psd = req.getParameter("psd");
        System.out.println(usr);
        resp.getWriter().print("您的用户id:"+usr+", 密码:"+psd);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
View Code

web.xml配置:

技术图片
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_4_0.xsd"
           version="4.0">
    <servlet>
        <servlet-name>MyServlet</servlet-name>
        
        <servlet-class>pers.eddy.hello.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
<filter>
    <filter-name>MyFilter</filter-name>
    <filter-class>pers.eddy.hello.MyFilter</filter-class>
    <init-param>
        <param-name>charset</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

    <filter-mapping>
        <filter-name>MyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
View Code

 

过滤器的使用

标签:click   extends   使用   www   map   dog   extend   pos   xtend   

原文地址:https://www.cnblogs.com/eddy-s/p/10742549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!