帮忙看看为什么没有输出

来源:3-1 [Java Web] 第一个过滤器案例

Workar

2017-08-17 11:14

//Filter类

package com.Filter;


import java.io.IOException;


import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;


public class MyfirstFilter implements javax.servlet.Filter {


@Override

public void destroy() {

System.out.println("销毁过滤器");

}


@Override

public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)

throws IOException, ServletException {

System.out.println("开始调用doFilter方法");

arg2.doFilter(arg0, arg1);

System.out.println("结束调用doFilter方法");

}


@Override

public void init(FilterConfig arg0) throws ServletException {

System.out.println("过滤器初始化");

}

}

//web.xml配置

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" 

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_2_5.xsd">

  <display-name></display-name>

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

  <filter>

  <filter-name>FirstFilter</filter-name>

  <filter-class>com.Filter.MyfirstFilter</filter-class>

  </filter>

  <filter-mapping>

  <filter-name>FirstFilter</filter-name>

  <url-pattern>/index.jsp</url-pattern>

  </filter-mapping>

</web-app>


//index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

<h1>过滤器</h1>

<hr>

</body>

</html>


写回答 关注

2回答

  • Workar
    2017-08-17 15:36:31

    Web版本用的3.0  已解决谢谢

    qq_与赠_...

    3.0版本就不行吗?

    2017-10-03 16:19:09

    共 1 条回复 >

  • Wadye
    2017-08-17 15:25:50

    不清楚,感觉可以的啊

Java Web开发技术应用——过滤器

本课程主要是从实际生活当中的过滤器入手,详细讲解了Java Web过滤器

70492 学习 · 258 问题

查看课程

相似问题