Java springmvc-JSTL-Session属性
我有一个Spring控制器,在这里我用变量设置会话对象Java springmvc-JSTL-Session属性,java,jsp,redirect,spring-mvc,jstl,Java,Jsp,Redirect,Spring Mvc,Jstl,我有一个Spring控制器,在这里我用变量设置会话对象 @RequestMapping("/index.html") public String indexHandler(HttpSession session, HttpServletRequest request, HttpServletResponse
@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
//这里声明了我的两个标记库,一个是核心,另一个是格式
它失败是因为
没有打印任何内容,c:redirect
标记没有正确关闭,也可能是因为该值没有括在引号中。你宁愿这样:
<c:redirect url="<%= session.getAttribute("url") %>" />
请注意,不需要强制转换
然而,使用老式的Scriptlet已经是十年前的事了。而是使用EL。然后,它就像:
<c:redirect url="${url}" />
您需要向我们提供更多信息,而不是说“这里它失败了”。它怎么会失败?是的,你是对的,巴鲁。我不应该使用scriptlet。还有另一个问题是选择正确的标记库。我将它从“”改为解决了这个问题