Servlet HttpSession et page web
Bonjour bonjour,
Je souhaite créer un espace membre sur mes pages.
Pour le moment je teste juste le servlet sur 2 pages : une page d'accueil avec le lien vers la page de login , on rentre un mail , pwd1 bidon, on revient sur la page d'accueil et normalement du texte est venu se rajouter / s'enlever..
Le soucis étant que je n'arrive justement pas à utiliser la variable mail dans mes différentes pages , comme si elle était vide, alors que mon servlet me semble juste.
Je vous link mon servlet, les pages utilisé et le header :
Le servlet HttpSession :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
@WebServlet(urlPatterns="/pagelogin")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
RequestDispatcher rd = req.getRequestDispatcher("/pagelogin.jsp");
rd.forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String mail2 = (String)req.getParameter("mail2");
HttpSession session = req.getSession(true);
session.setAttribute("mail2", mail2);
req.getRequestDispatcher(req.getContextPath() + "/Welcome.jsp");
}
} |
La page d'accueil :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
<%@ 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>
<link rel="stylesheet"
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<blockquote>
<br>
<h1>
Welcome
</h1>
<c:if test="${empty mail2}">
If you are speaker and have already an account, please <a href="register.jsp">authentificate you</a> to manage your intervention
<br>
If you doesn't have an account, please <a href="pagelogin.jsp">register you</a> !
</c:if>
<%@ include file="/fragments/header.jsp" %>
</body> |
Le page ou je me log :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style>
</style>
</head>
<body>
<br /><br />
<form id="myForm" action="Welcome.jsp" method="POST">
<br /><br />
<input type="text" name="mail2" />
<br /><br />
<input type="text" name="pwd1" />
<br /><br />
<input type="submit" value="Login" class="btn primary" />
</form>
<script>
</script>
<%@ include file="/fragments/header.jsp" %>
</body>
</html> |
Et mon header ( qui est censé afficher une barre différente selon la valeur de mail2 ):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
<style type="text/css">
</style>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
</head>
<body>
<% if(session.getAttribute("mail2") == null) {%>
<div class="topbar">
<div class="fill">
<div class="container">
<a href="<%= application.getContextPath() %>/Welcome.jsp" class="brand" >Welcome</a>
<ul class="nav">
<li><a href="<%= application.getContextPath() %>/register.jsp">Register</a></li>
<li><a href="<%= application.getContextPath() %>/pagelogin.jsp">Login</a></li>
</ul>
</div>
</div>
</div>
<% } else { %>
<div class="topbar">
<div class="fill">
<div class="container">
<a href="Welcome.jsp" class="brand" >Welcome</a>
<ul class="nav">
<li><a href="<%= application.getContextPath() %>/newintervention.jsp">New intervention</a></li>
<li><a href="<%= application.getContextPath() %>/listintervention.jsp">My intervention</a></li>
<li><a href="<%= application.getContextPath() %>/logout">Logout</a></li>
</ul>
</div>
</div>
</div>
<% } %>
</body> |
Merci d'avance