java中心servlet自定义处理请求循环问题

时间:2019-01-18 16:28:11

标签: java servlets java-ee filter requestdispatcher

我有一个中心servlet来自定义处理我的所有请求。 这是我的代码:

@WebServlet(name = "/servletDispatcher", value = "/*")
public class ServletDispatcher extends HttpServlet {

@Override
protected void service(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
   if(request.getPathInfo().equals("hello")){
      response.sendRedirect("index.jsp");
   }
}

但是问题是当我发送重定向或调度时,它再次进入我的servlet,然后没有任何显示,因为我的条件没有执行! 像这样的东西:

first time pathInfo -> /hello
send redirect to "index.jsp"
then pathInfo -> /index.jsp

我需要使用pathInfo()处理请求以重定向或调度视图。

0 个答案:

没有答案