[英]Print a value using JSP and Expression Language (EL)
我有一個servlet,我想用JSP文件從servlet中打印一些數據,而且我必須使用強制性的表達語言。
我在servlet中有以下代碼:
String saludo="hi";
req.setAttribute("exito",saludo);
我的JSP文件中有這個:
${exito}
我也嘗試過這樣做:
${requestScope.exito}
但是,當我嘗試通過瀏覽器(Google Chrome)看到它時,沒有看到hi
,而是看到了
${exito}
我究竟做錯了什么?
當您向JSP發送信息時,您需要取消當前對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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.