java - Use EL ${XY} directly in scriptlet <% XY %> -


in project i've asign variable every time jsp being opened. tried scriptlets <% %> in jsp , el ${} gives variable back.

but seems not working.

 <% string korrekteantwort=${frage.korrekteantwort};%>  <%session.setattribute("korrekteantwort", korrekteantwort);%> 

there error after korrekteantwort=${}, isn't possible asign directly variable el in scriptlet?

you're mixing scriptlets , el , expecting run "in sync". won't work. the 1 oldschool way of writing jsps , the other modern way of writing jsps. should use 1 or other, not both.

coming concrete question, under hoods, el resolves variables pagecontext#findattribute(). same in scriptlets.

frage frage = (frage) pagecontext.findattribute("frage"); session.setattribute("korrekteantwort", frage.getkorrekteantwort()); 

however, said, oldschool way of using jsps , not "best" way the functional requirement you've had in mind, didn't tell about. modern jsp way using jstl <c:set>:

<c:set var="korrekteantwort" value="${frage.korrekteantwort}" scope="session" /> 

this available in session scope ${korrekteantwort} line on, line of scriptlet does.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -