Posts

Showing posts with the label El

Access Java / Servlet / JSP / JSTL / EL Variables In JavaScript

Answer : You need to realize that Java/JSP is merely a HTML/CSS/JS code producer. So all you need to do is to just let JSP print the Java variable as if it is a JavaScript variable and that the generated HTML/JS code output is syntactically valid. Provided that the Java variable is available in the EL scope by ${foo} , here are several examples how to print it: <script>var foo = '${foo}';</script> <script>someFunction('${foo}');</script> <div onclick="someFunction('${foo}')">...</div> Imagine that the Java variable has the value "bar" , then JSP will ultimately generate this HTML which you can verify by rightclick, View Source in the webbrowser: <script>var foo = 'bar';</script> <script>someFunction('bar');</script> <div onclick="someFunction('bar')">...</div> Do note that those singlequotes are thus mandatory in ord...

Are Session And SessionScope The Same In JSP EL?

Answer : With expression language (EL), the scope items are value maps of attributes in the objects that they refer to. For instance, the requestScope is a map representation of values in the request object. This is explained in pretty clear detail on this page: Java Servlet and JSP. If you read through the EL sections, you'll notice a point about request vs request scope here: The requestScope is NOT request object. I would recommend reading through this page to get a better understanding of servlet/jsp in general. As far as how the ActionContext relates to these items, it is really a wrapper used by struts to encapsulate the servlet. You can read more specifics about it here: Accessing application, session, request objects. There have been some references to implicit values given here, but I feel like just saying it's implicit doesn't really explain much. When you are using EL to access servlet variables, you can explicitly declare which scope you want to referen...