我写了一个过滤器如下:
@WebServlet(urlPatterns = {"/jsp/buy/buy-uploadlist.jsp", "/jsp/buy/buy-buylist.jsp"})
public class LoginValidationFilter extends HttpServlet {
protected FilterConfig filterConfig;
public LoginValidationFilter() {
}
private String encode = "UTF-8";// 默认UTF-8编码
protected void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
//request.setCharacterEncoding("UTF-8");
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse resp = (HttpServletResponse)response;
HttpSession session = req.getSession();
PrintWriter out = response.getWriter();
String reqURL = req.getServletPath();
String loginMess = (String)session.getAttribute("login");
if(loginMess == null || !loginMess.equals("true")){
resp.sendRedirect(req.getContextPath() + "/visiterror.jsp");
return;
}
chain.doFilter(request,response);
}
public void init(FilterConfig fConfig) throws ServletException{
this.filterConfig = fConfig;
}
}
然后启动TOMCAT在尝试访问这两个页面是始终提示”405此URL不支持Http方法GET“,我在网上查到的重写方法没有效果,请问可能是什么原因?非常感谢