When to use requestScope in jstl?
Jstl variable set in request scope in jsp
<c:set var="name" value="Tiger" scope="request" /> This variable is available from jspf included in this jsp. So, is there a difference in accessing a variable in these two ways?
1) <c:out value="${name}" /> 2) <c:out value="${requestScope.name}" /> When to use requestScope?
You use requestScope when you absolutely do not want your object to come from a request, and not from a page, session, or application area. Inded, using ${name} , will look for the name attribute on the page, then in the request, then in the session, then in the application.
Let's say that some other code in the JSP sets the name attribute in the page area. But you want to access the name in the request: you are forced to use requestScope.
Suppose a session can have a name attribute. Do not use requestScope.name to return a session name if the JSP forgot to set the name attribute in the request area.
If the purpose of the JSP fragment is to access something set in the enclosing JSP, perhaps that JSP fragment should be a JSP tag, and you should pass that name as an argument to that tag.
As part of my research (I'm also new to jstl), the request area can set values ββfor requesting a page from the response page, for example, suppose we have a page called index.jsp and its action page is index_action.jsp
if we set the values ββon the action page
<c:set var="nme" scope="request" value="Janaka aravinda"/> <% request.getRequestDispatcher("index.jsp").forward(request, response); %> (// I created the nme variable and set its value as Janaka aravinda . And back to reload the request page (index.jsp))
Now we can call nme in the variable index.jsp nme , as follows Request value
<c:out value="${nme}"/>