訪問 https://localhost:8085/test/jsapi.jsp?apple=1,頁面用 ${apple} 取不到值,但另一個項目 https://localhost:8085/my_account/confirmOrder?apple=1 卻能取到。
EL 表達式 ${apple} 查找順序:Page → Request → Session → Application 域屬性,**不會自動查詢請求參數**。另一個項目能取到,是因為 Controller/Servlet 顯式做了 request.setAttribute("apple", ...)。
${param.apple}
${paramValues.apple}
${param['apple']}
param 是 JSP 隱含對象,封裝 request.getParameterMap()。
request.setAttribute("apple", request.getParameter("apple")),前端才能用 ${apple}。${param.apple},無需後端額外代碼。記住:**EL 取參數必須帶 param. 前綴。**