JSP access global variables
This question already has an answer here:
You are using <% // statements %>
to print the values, but using we can embed java code into jsp
. <%= //expressions %>
using this we can embed the java expression to jsp and with this we can print the values or we can assign the values to html elements.
Find the below code:
<h1>
Transfer successful! Customer
<%= session.getAttribute("name");%>
received $
<%= session.getAttribute("amount");%>.
My suggestion is avoid java code in jsp, as much as possible, you can achieve the above using JSTL and EL. Find the below example:
<h1>
Transfer successful! Customer
${requestScope.name}
received $
${requestScope.amount}
</h1>
You can use ${sessionScope.name}
if you get value from the session.
上一篇: 关于在JSP中使用脚本
下一篇: JSP访问全局变量