I am trying display a session attribute on this jsp page:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page session="true" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>title</title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<c:choose>
<c:when test="${error}">
Erro.
<br />
</c:when>
<c:otherwise>
<c:out value="${sessionScope.login}"/> | <a href="<c:url value = "/logout"/>">Sair</a>.
<br />
</c:otherwise>
</c:choose>
<script src="/js/script.js"></script>
</body>
</html>
this page is forwarded from this servlet:
package org.loja.app.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class LoginServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String login = request.getParameter("login");
String password = request.getParameter("password");
if(password.equals("123")) {
HttpSession session = request.getSession();
session.setAttribute("login", login);
request.setAttribute("error", false);
request.getRequestDispatcher("/WEB-INF/jsp/index.jsp").forward(request, response);
} else {
request.setAttribute("error", true);
request.getRequestDispatcher("/WEB-INF/jsp/index.jsp").forward(request, response);
}
}
}
when I open the page on the browser, instead of the attribute value, I get the text ${sessionScope.login}
.
What I am missing here?
{test}
` *can't edit my previous comment, forgot to add the "test" before "hello world" – Jonathan Laliberte Oct 29 '18 at 19:50