...">

How to access request attributes in JSP?

I am currently using:

<% final String message = (String) request.getAttribute ("Error_Message"); %> 

and then

 <%= message %> 

However, I am wondering if this can be done using EL or JSTL instead of using a script.

+48
jsp el jstl
Feb 06 '11 at 10:18
source share
3 answers

EL expression:

 ${requestScope.Error_Message} 

JSP EL has several implicit objects. See Expression Language in the Implicit Objects header.

+76
Feb 06 '11 at 10:45
source share

Using JSTL:

 <c:set var="message" value='${requestScope["Error_Message"]}' /> 

Here var sets the variable name and request.getAttribute equals requestScope . But it is not important. $ {Error_Message} will give you the same result. He will seek all possibilities. If you want to perform some operation on the contents that you take with Error_Message , you need to do this with a message . as below.

 <c:out value="${message}"/> 
+1
May 18 '16 at 7:54 a.m.
source share

Just noting this here if anyone else has a similar problem.
If you send the request directly to the JSP using the Apache Tomcat web.xml configuration, then ${requestScope.attr} does not seem to work, instead, ${param.attr} contains the attr request attribute.

0
Jun 21 '17 at 13:07 on
source share



All Articles