當你發送信息到JSP,你需要dispacth當前請求JSP,我嘗試了上面的代碼,我沒有任何問題,這是我的代碼:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String saludo="hi";
req.setAttribute("exito",saludo);
req.getRequestDispatcher("MyPage.jsp").forward(req, resp);
}
而且這是MyPage.jsp代碼
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Title</title>
</head>
<body>
${exito}
</body>
</html>
[在JSP不工作表達式語言(http://stackoverflow.com/questions/2168832/expression-language-in-jsp-not-working) –
的重複嘗試使用JSTL include <%@ taglib prefix =「c」uri =「http://java.sun.com/jsp/jstl/core」%>然後嘗試 –
user1769790