0
我是Java服務器編程的新手,我試圖使用Google應用引擎。如何使用從servlet獲取數據到JSP
下面的代碼是一個servlet:
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setAttribute("message", "Hi from servlet!");
req.getRequestDispatcher("/my_page.jsp").forward(req, resp);
}
而下面的代碼是在my_page.jsp
:
<%= request.getAttribute("message") %>
在哪裏我希望看到Hi from servlet!
在結果頁中,我看到null
。
(如果我嘗試使用${message}
,我得到任何輸出)
什麼是從一個servlet到JSP獲取數據的正確方法?
這是正確的方法。你有什麼錯誤嗎? – 2012-02-19 22:56:51
沒有錯誤,輸出只是一個「空」 – andypaxo 2012-02-19 22:59:39