I tried several solution even here on StackOverflow but none seems to work: I want to pass a string from a Servlet to a JSP and show it with EL.
I created a simple plain project on Netbeans and this is the code I added:
Servlet Code:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String message = "Hello";
request.setAttribute("message", message);
RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
dispatcher.forward(request, response);
}
JSP Code:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<h2 style="border: 2px solid brown; width: 20%"> Message is: ${message} </h2>
</body>
</html>
What get me frustated is that even for the documentation (Oracle Api Reference and a HeadFirst O'Reilly Guide) this should be straightforward, but I simply get no text, even if I use a scriptlet. I tried both Glassfish and TomEE