Filter是什么?
Filter的意思为“过滤器”,是处于客户端与服务器资源文件之间的一道过滤网,在访问资源文件之前,通过一系列的过滤器对请求进行修改、判断等,把不符合规则的请求在中途拦截或修改;也可以对响应进行过滤,拦截或修改响应。
Filter映射:
package cn.itacst.chapter08.filter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
-
Servlet implementation class forwartServlet
*/
@WebServlet("/forwartServlet")
public class forwardServlet extends HttpServlet {
private static final long serialVersionUID = 1L;/**
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.getRequestDispatcher("/first.jsp").forward(request,response);
}
/**
- @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
}
JSTL
Apache Tomcat安装JSTL 库步骤如下:
从Apache的标准标签库中下载的二进包(jakarta-taglibs-standard-current.zip)。
官方下载地址:http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/
本站下载地址:jakarta-taglibs-standard-1.1.2.zip
下载 jakarta-taglibs-standard-1.1.2.zip 包并解压,将 jakarta-taglibs-standard-1.1.2/lib/ 下的两个 jar 文件:standard.jar 和 jstl.jar 文件拷贝到 /WEB-INF/lib/ 下。
将 tld 下的需要引入的 tld 文件复制到 WEB-INF 目录下。
接下来我们在 web.xml 文件中添加以下配置:
http://java.sun.com/jsp/jstl/fmt
/WEB-INF/fmt.tld
http://java.sun.com/jsp/jstl/fmt-rt
/WEB-INF/fmt-rt.tld
http://java.sun.com/jsp/jstl/core
/WEB-INF/c.tld
http://java.sun.com/jsp/jstl/core-rt
/WEB-INF/c-rt.tld
http://java.sun.com/jsp/jstl/sql
/WEB-INF/sql.tld
http://java.sun.com/jsp/jstl/sql-rt
/WEB-INF/sql-rt.tld
http://java.sun.com/jsp/jstl/x
/WEB-INF/x.tld
http://java.sun.com/jsp/jstl/x-rt
/WEB-INF/x-rt.tld
Filter是什么?
Filter的意思为“过滤器”,是处于客户端与服务器资源文件之间的一道过滤网,在访问资源文件之前,通过一系列的过滤器对请求进行修改、判断等,把不符合规则的请求在中途拦截或修改;也可以对响应进行过滤,拦截或修改响应。
Filter映射:
package cn.itacst.chapter08.filter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
-
Servlet implementation class forwartServlet
*/
@WebServlet("/forwartServlet")
public class forwardServlet extends HttpServlet {
private static final long serialVersionUID = 1L;/**
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.getRequestDispatcher("/first.jsp").forward(request,response);
}
/**
- @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
- @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
}