标签:ide 过滤器 exce extend last ram vax ext url
一、web.xml
(1)指定过滤的Servlet类
(2)配置过滤规则,过滤以.mail结尾的链接
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>mailServlet</servlet-name> <servlet-class> com.zit.rfid.app.prms.business.service.servlet.MailServlet </servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mailServlet</servlet-name> <url-pattern>*.mail</url-pattern> </servlet-mapping> </web-app>
二、Servlet过滤类
当链接中包含以.mail结尾的链接,就执行下面这个Servlet
package com.zit.rfid.app.prms.business.service.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MailServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StringBuffer mailUrl = new StringBuffer();
String reqUrl = request.getRequestURL().substring(0, request.getRequestURL().lastIndexOf(".mail"));
mailUrl.append(reqUrl)
.append(".html?id=")
.append(request.getParameter("id"));
Cookie cookie = new Cookie("mailUrl", mailUrl.toString());
//生命周期:秒
cookie.setMaxAge(3600);
response.addCookie(cookie);
response.sendRedirect(mailUrl.toString());
}
}
(1) 获取该链接,重新组装链接地址(比如:把.mail换成.html,因为.mail是过滤规则)
(2)将该链接加入到Cookie
(3)在前台JS里,比如登陆成功后的函数里:获取该Cookie,重新跳转到该链接即可
外部点击链接,登陆后,直接跳转到该链接(过滤器 + Cookie实现)
标签:ide 过滤器 exce extend last ram vax ext url
原文地址:https://www.cnblogs.com/Donnnnnn/p/9044710.html