Reputation: 4451
I have a servlet, and I want to print some data from the servlet with a JSP file, and I have to use compulsory the Expression Language.
I have this code in the servlet:
String saludo="hi";
req.setAttribute("exito",saludo);
And I have this in my JSP file:
${exito}
And I also tried with this:
${requestScope.exito}
But when I try to see it with my browser (Google Chrome), instead of seeing hi
, I see
${exito}
What am I doing wrong?
Upvotes: 2
Views: 5515
Reputation: 2738
When you are sending information to the JSP you need to dispacth the current request to the JSP, I try the above code and I don't have any problem, this is my code:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String saludo="hi";
req.setAttribute("exito",saludo);
req.getRequestDispatcher("MyPage.jsp").forward(req, resp);
}
And this is the code for 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>
Upvotes: 2