2

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.setAttribute("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
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
sv1
  • 79
  • 3
  • 9

1 Answers1

2

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}" />
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Yes you are right Balu. I should not be using scriptlets. Also there was another issue that was there which was selecting the right taglib.I changed it from "<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c'%>" to <%@ taglib uri='http://java.sun.com/jstl/core' prefix='c'%> That solved the issue – sv1 Oct 09 '10 at 21:05