uniapp开发app框架在提升开发效率中的独特优势与应用探索
934
2022-11-20
HTTP系列之http链接强转为https链接Filter
import java.io.IOException;import java-.URI;import java-.URISyntaxException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.annotation.WebFilter;import javax.servlet.javax.servlet.lombok.extern.slf4j.Slf4j;/** * *
* HTTP过滤器,根据请求协议进行过滤,** @author Nicky * @date:2018年01月19日 下午11:55:57 *
* 修改记录 * 修改后版本: 修改人: 修改日期: 修改内容: **/@Slf4j@WebFilter(filterName="/Http2HttpsFilter",urlPatterns="/*")public class Http2HttpsFilter implements Filter { public Http2HttpsFilter() { } @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest)request; HttpServletResponse res = (HttpServletResponse)response; //获取请求协议 String scheme = request.getScheme(); log.info("转换前的链接为:"+req.getRequestURL()+"?"+req.getQueryString()); // try{ if(req.getQueryString()!=null && !"".equals(req.getQueryString())){ reqUri = new URI(req.getRequestURL()+"?"+req.getQueryString()); }else{ reqUri = new URI(req.getRequestURL().toString()); } newUri = new URI("reqUri.getUserInfo(), reqUri.getHost(), reqUri.getPort(), reqUri.getPath(), reqUri.getQuery(), reqUri.getFragment()); }catch(URISyntaxException e){ e.printStackTrace(); } //根据请求协议进行过滤,请求协议为HTTP的都进行过滤 if(scheme.equals(" log.info("转换后的链接为:"+newUri.toString()); //重定向 res.sendRedirect(newUri.toString());// res.sendRedirect(sbd.toString()); //chain.doFilter(req, res); return; }else{ chain.doFilter(req, res); } } @Override public void init(FilterConfig fConfig) throws ServletException { }}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~