linkfilter.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 122 行
JAVA
122 行
package com.redmoon.forum;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import cn.js.fan.util.StrUtil;public class LinkFilter implements Filter { FilterConfig config; public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException { if (req instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) req; String uri = request.getRequestURI(); if (uri.endsWith(".html")) { int p = uri.indexOf("f-"); if (p > 0) { char mode = uri.charAt(p + 2); if (mode=='0' || mode=='1') { int p2 = p + 4; int q = uri.indexOf("-", p2); if (q > 0) { String boardcode = uri.substring(p2, q); String pageNum = ""; String threadType = "" + ThreadTypeDb.THREAD_TYPE_NONE; int r = uri.indexOf("-", q + 1); if (r==-1) { pageNum = uri.substring(q + 1, uri.length() - 5); } else { pageNum = uri.substring(q + 1, r); int pp = r + 1; int qq = uri.length() - 5; if (pp < qq) { threadType = uri.substring(pp, qq); } } if (StrUtil.isNumeric(pageNum)) { String page; if (mode == '0') page = "listtopic.jsp"; else page = "listtopic_tree.jsp"; String url = page + "?boardcode=" + boardcode + "&CPages=" + pageNum + "&threadType=" + threadType; RequestDispatcher rd = req. getRequestDispatcher( url); rd.forward(req, res); return; } } } } else { p = uri.indexOf("t-"); if (p>0) { char mode = uri.charAt(p + 2); if (mode == '0') { p = p + 4; int q = uri.indexOf("-", p + 1); if (q > 0) { String rootid = uri.substring(p, q); String pageNum = uri.substring(q + 1, uri.length() - 5); if (StrUtil.isNumeric(pageNum)) { String url = "showtopic.jsp?rootid=" + rootid + "&CPages=" + pageNum; RequestDispatcher rd = req. getRequestDispatcher(url); rd.forward(req, res); return; } } } else if (mode=='1') { p = p + 4; int q = uri.indexOf("-", p + 1); if (q > 0) { String rootid = uri.substring(p, q); String showid = uri.substring(q + 1, uri.length() - 5); if (StrUtil.isNumeric(showid)) { String url = "showtopic_tree.jsp?rootid=" + rootid + "&showid=" + showid; RequestDispatcher rd = req.getRequestDispatcher(url); rd.forward(req, res); return; } } } } } } chain.doFilter(req, res); } } public void init(FilterConfig config) throws ServletException { this.config = config; } public void destroy() { this.config = null; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?