EL表示式無法獲取後臺java傳過來的值
阿新 • • 發佈:2019-02-15
問題:後臺程式碼如下:
public class HelloServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("222222"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTime = dateFormat.format(new Date()); req.setAttribute("currentTime",currentTime); req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req,resp); } }
前端程式碼:
<%@ page pageEncoding="UTF-8" %> <html> <head> <title>hello</title></head> <body> <h1>Hello</h1> <h2>當前時間 : ${currentTime}</h2> </body> </html>
輸出為:
Hello
當前時間 : ${currentTime}
問題原因:EL表示式不能夠正確執行、解析。只需要加入:
<%@ pageisELIgnored="false" %>
就正常可以訪問到值