RequestDispatcher sur un servlet
Bonjour,
J'ai une page html et un servlet.
Le formulaire de ma page html envoie au servlet des paramètres, lequels redirige vers une autre page html,si le client n'a pas rentrer le bon email
, parcequ'il ne c'est pas enregistré. Mais mon soucis c'est que ça me renvoie une page blanche ?
Le fichier html:
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| <!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=UTF-8" />
<title>Site de maintenance -</title>
<style type="text/css">
#formulaire {
border-width:thin;
width:80%;
border:1px dashed red;
padding-right:20px;
background-color :#FFF;
}
h1{
margin:0 0 0 50px;
color:gray;
font:arial;
}
h2{
color:green;
}
</style>
</head>
<body><center>
<form action="/ProjetIteration1/TechSupportServlet" method="post" ><br>
<div id="formulaire">
<h1>Support technique</h1>
<br><br />
<table style="width:700px;">
<tr>
<td ALIGN="right">Email :</td>
<td><input type='text'name="mail" ALIGN="left" size="30"/></td>
</tr>
<tr>
<td ALIGN="right">Logiciel : </td>
<td><select name='logiciel'>
<option value='excel'>Microsoft Excel</option>
<option value='word'>Microsoft Word</option>
<option value='powerpoint'>Microsoft PowerPoint</option>
</select></td>
<td ALIGN="right">Systeme d'exploitation : </td>
<td><select name='os' size="1">
<option value='linux'>Linux</option>
<option value='windows'>Windows XP</option>
<option value="MacOS">Mac Os</option>
</select></td>
</tr>
</table>
<h2>
Description du probleme : <br>
<textarea name="probleme" cols="50" rows="10" wrap="virtual"></textarea><br>
</h2>
<input type="submit" value="Soumettre la requete" /><br><br>
</div>
</form>
</body>
</html> |
Mon servlet qui devrai rediriger Mais qui affiche une page blanche, comme neige.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
package ProjetIteration;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class TechSupportServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{
String userName,password,mailF,logicielF,systemeF,problemeF;
String protocol;
private String urlConnection = "jdbc:mysql://localhost:3306/frontal";
private String loginConnection = "root";
private String passConnection = "xav";
public void init()
{
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.print("Driver JDBC chargé");
}
catch (ClassNotFoundException e) {
System.out.print(e.toString());
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
mailF=request.getParameter("mail");
logicielF=request.getParameter("logiciel");
systemeF=request.getParameter("systeme");
problemeF=request.getParameter("probleme");
try{
Connection con=DriverManager.getConnection(protocol,userName,password);
//System.out.println("got connection");
//initialisation de la session
HttpSession session=request.getSession(true);
session.setAttribute("mail",new String(mailF));
session.setAttribute("logiciel",new String(logicielF));
session.setAttribute("systeme",new String(systemeF));
session.setAttribute("probleme",new String(problemeF));
Statement s=con.createStatement();
String sql="select mail from user where mail='"+mailF+"'";
System.out.println(sql);
Statement req=con.createStatement();;
ResultSet result=req.executeQuery(sql);
if (result.next())
{
System.out.println("Ok , je t'ai trouve");
RequestDispatcher rd=request.getRequestDispatcher("/ReponseServlet");
rd.forward(request,response);
}
else
{
System.out.println("Le profile n'existe pas");
RequestDispatcher rd=request.getRequestDispatcher("/ProjetIteration/register.html");
rd.forward(request,response);
}
req.close();
con.close();
}
catch(SQLException e){
String message="Error."+e.toString();
}
}
} |
Merci
EDIT ->
Par ailleurs j'ai essayé : [toujours pas de redirection, mais la page blanche]
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| if (result.next())
{
System.out.println("Ok , je t'ai trouve");
response.sendRedirect("/ProjetIteration/ReponseServlet");
//getServletContext().getRequestDispatcher("/ProjetIteration/ReponseServlet").forward(request,response);
}
else
{
System.out.println("Le profile n'existe pas");
response.sendRedirect("/ProjetIteration/register.html");
//getServletContext().getRequestDispatcher("/ProjetIteration/register.html").forward(request, response);
} |