Get URL of page requested that caused a 404

前端 未结 2 1032
梦如初夏
梦如初夏 2021-01-12 16:54

How would I get the URL of the page that was requested that caused the 404 error?

For example, I type I go to http://example.com/path/does/not/exist/index.jsp I alre

2条回答
  •  执念已碎
    2021-01-12 17:26

    I'm using JDK 8 and GlassFish 4, and

    request.getAttribute("javax.servlet.forward.request_uri")
    

    always returned null for me. What eventually did work was

    request.getAttribute("javax.servlet.error.request_uri")
    

    I'm not sure why the attribute name is different, but in case the name I listed doesn't work on your setup, here's the code I used to find it...

        Enumeration names = request.getAttributeNames();
    
        while(names.hasMoreElements()){
            String name = names.nextElement();
            Object attr = request.getAttribute(name);
    
            System.out.println("Req:  "+name + " : "+attr);
        }
    

提交回复
热议问题