0

At the moment I am trying to make my own canonical links in Java web.

I got this in my web.xml

<servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

ControllerServlet will call a factory that will use the getPathInfo() to call the correct class to handle this. The method that will handle the requests looks like

public void handleRequest(HttpServletRequest request, HttpServletResponse response) {
    try {
        RequestDispatcher view =  request.getRequestDispatcher("../Overview.jsp");
        view.forward(request, response);
    } catch (Exception ex) {
         System.out.println("error");
    }
}

Now when I want to visit my page I will surf to

http://localhost/firstfolder/overview

The pathinfo I get is /firstfolder/overview, this redirects correctly to /Overview.jsp but after that it keeps redirecting to /Overview.jsp and ultimately crash. Leaving the end user with an empty page. Any idea how I can stop this unlimited looping and just serve the page?

Tom
  • 403
  • 3
  • 14
  • "it keeps redirecting to /Overview.jsp and ultimately crash" <-- this is normal: URL pattern `/*` also matches `/Overview.jsp`; you have a loop – fge Mar 15 '14 at 21:37
  • But how can I tell the Controller to not redirect but use it? I've even tried with using regex on *jsp$. He detects the regex but will continue redirecting. – Tom Mar 15 '14 at 22:20
  • First: what is the argument to `url-pattern`? Is that a glob? A pure regex? – fge Mar 15 '14 at 22:30
  • I'm not quite sure, I think it is more of a glob because not all regex functions work in it. It is the default stuff for java url patterns in web.xml – Tom Mar 16 '14 at 13:15
  • OK, I see. Then in your code, check that the path isn't `"/Overview.jsp"` before proceeding – fge Mar 16 '14 at 14:17

0 Answers0