What is the simplest way to display httpServletResponse.sendError(403, “My Message”) status from JSTL

后端 未结 2 464
自闭症患者
自闭症患者 2020-12-17 01:48

I have a servlet which does some error checking and if something is wrong I will typically do this:

response.sendError(403, \"My message\")
return;
<         


        
相关标签:
2条回答
  • 2020-12-17 02:07

    The scriptlet:

    <%= request.getAttribute("javax.servlet.error.message") %>
    

    can be translated to the following EL:

    ${requestScope['javax.servlet.error.message']}
    

    The brace notation bean['foo.bar'] is very useful if you have dots in Map or scoped key names, because bean.foo.bar obviously doesn't return the desired Map or scoped value.

    0 讨论(0)
  • 2020-12-17 02:08

    Declare an JSTL tag with an attribute "var", which will have an exception object(if there any error occured between the body of tags) at the end of tag, which have stackTrace and message properties.

    <c:catch var="myException">
    <%int x=10/0; %>
    </c:catch>
    
    <c:if test="${myException !=null}">
    There was an exception: ${myException.message} 
    </c:if>
    
    0 讨论(0)
提交回复
热议问题