IllegalStateException : Impossible d'utiliser faire-suivre (forward)
Bonjour,
j'ai un problème avec Tomcat 6.0.18 et eclipse 3.4 dont je n'arrive pas à me dépatouiller depuis plusieurs jours, malgré toute la littérature trouvée sur le web.
Après avoir identifié un utilisateur, je voudrais le rediriger sur une page de bienvenue ou autre selon le cas. J'ai donc 3 pages : login.jsp, bienvenue.jsp et nologin.jsp, plus une servlet TraiterLogin.java. Chaque fois que je veux rediriger l'utilisateur, Tomcat me sort :
Citation:
java.lang.IllegalStateException: Impossible d'utiliser faire-suivre (forward) après que la réponse ait été envoyée
J'ai regardé partout, je ne vois absolument pas où, quand et comment j'ai pu envoyer une réponse avant ... J'ai essayé de mettre mon code dans doGet(), dans doPost(), ça ne change rien.
Voici ma servlet :
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
|
protected void service (HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
super.service (request, response);
HttpSession session = request.getSession (true);
String login = request.getParameter ("login");
String pwd = request.getParameter ("pwd");
EntityManager em = PersistenceUtil.getInstance ( ).getEntityManager ( );
EntityTransaction tx = em.getTransaction ( );
tx.begin ( );
User user = em.find (User.class, login);
tx.commit ( );
em.close ( );
if (user.getPassword ( ).equals (pwd)) {
System.out.println ("OK");
session.getServletContext ( )
.getRequestDispatcher ("/bienvenue.jsp")
.forward (request, response);
} else {
System.out.println ("HS");
session.getServletContext ( ).getRequestDispatcher ("/nologin.jsp").forward (request,
response);
}
} |
et voici mes pages jsp, générées par eclipse :
login.jsp
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
|
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Identification</title>
</head>
<body>
<form method="post" action="TraiterLogin">
<table cellpadding="2" >
<thead>
<tr ><td align="center" colspan="2"><h2>Identification</h2></td></tr>
</thead>
<tr>
<td>Login :</td><td><input type="text" name="login"></input></td>
</tr><tr>
<td>Mot de passe :</td><td><input type="password" name="pwd"></td>
</tr><tr>
<td colspan="2" align="center"><input type="submit" value="Connexion"></input></td>
</tr>
</table>
</form>
</body>
</html> |
et nologin.jsp (La page de bienvenue est la même, au message près) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h1>Raté, tu feras mieux la prochaine fois !</h1>
</body>
</html> |
Un grand merci à tous ceux qui m'aideront !