I am trying to pass a value from the session object to a custom tag <l:LoginStatus userId="<% out.print((String)session.getAttribute("userId")); %>"/>
Why does this lin开发者_如何学JAVAe give me the error:
org.apache.jasper.JasperException: /index.jsp(1,1) /header.jsp(64,131) equal symbol expectedWhen I pass a hard coded value like this <l:LoginStatus userId="4"/>
Everything works fine.
It doesn't make any sense to me, I thought using out.print
would make =
uneccessary.
An alternative is to just use EL. That yields much cleaner code.
<l:LoginStatus userId="${userId}" />
It should be:
<%= (String)session.getAttribute("userId") %>
In general it is much better practice to do things this way, instead of writing directly to a page. Besides, things don't work exactly as you seem to think they do.
As you're printing the value of the an expression, you should make the statement as
<l:LoginStatus userId="<%=out.print((String)session.getAttribute("userId"))%>"/>
or
<l:LoginStatus userId="<%=out.print(session.getAttribute("userId")).toString()%>"/>
精彩评论