How to show the requested URL in a JSP error page?

前端 未结 1 1855
孤城傲影
孤城傲影 2021-01-13 16:10

In the error page I would like to display the URL what the user requested.

In my web.xml:

&l         


        
1条回答
  •  不要未来只要你来
    2021-01-13 16:29

    Here is a simple example of JSP error page that shows the error code and the URL of the requested page:

    404.jsp:

    <%@ page language="java" isErrorPage="true" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    
    
    
        Error page
        
    
    
        
        

    404 Page Not Found.


    Error code: ${pageContext.errorData.statusCode}

    Request URI: ${pageContext.request.scheme}://${header.host}${pageContext.errorData.requestURI}



    Useful reading:

    • "JSP.1.4 Error Handling" section in the JavaServer Pages Specification (JSR 245).
    • Handling JSP Page Errors (from the official Java EE 5 Tutorial)

    P.S.
    The use of scriptlets inside JSP is highly discouraged. Read this post.

    0 讨论(0)
提交回复
热议问题