Spring MVC - JSTL - Session Attribute
I have a Spring Controller where I am setting a session object with variables .
@RequestMapping("/index.html")
public String indexHandler(HttpSession session,
HttpServletRequest request,
HttpServletResponse response){
session = request.getSession(true);
session.setAttrib开发者_如何学Cute("country","India");
session.setAttribute("url", getAuthURL());//getAuthURL returns a string
return "tempJSP";
//tempJSP is a JSP under webroot/jsps/ and this is configured in Dispatcher servlet
}
tempJSP.jsp
//My 2 taglibs are declared here one is core and other is format
<c:redirect url=<%(String)session.getAttribute("url")%> //Here it fails
It fails because a <% %>
doesn't print anything, the c:redirect
tag isn't properly closed and possibly also because the value isn't enclosed in quotes. You rather want this:
<c:redirect url="<%= session.getAttribute("url") %>" />
Note that the cast is unnecessary.
However, using old fashioned scriptlets is discouraged since a decade. Rather use EL. It's then as easy and nice as:
<c:redirect url="${url}" />
精彩评论