Acces à mysql (servlet+jsp) sous eclipse
info-rmaticienne
Messages postés
11
Date d'inscription
Statut
Membre
Dernière intervention
-
info-rmaticienne Messages postés 11 Date d'inscription Statut Membre Dernière intervention -
info-rmaticienne Messages postés 11 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai un projet en J2EE et jessai de recuperer les champs depuis une page html et à laide dune page JSP et une servlet je veux acceder a ma base donnèes mais ça marche po il menvoi directement vers la page derreur je serai vraiment reconaissace si vs pouvez maidè :) voila le code :
page jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page errorPage="Erreur.jsp" %>
<jsp:useBean id="Authent" class="Beans.Authentification"></jsp:useBean>
<!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=ISO-8859-1">
<title>Authentificaion</title>
</head>
<body >
<%
String CodeErreur="";
String Logine=request.getParameter("Login");
String Pwd=request.getParameter("Pwd");
if(Logine=="" || Pwd==""){
throw new Exception("vous avez oublié de précisé votre login ou votre mot de passe!!!");
}
else{
Authent.setlogin(Logine);
Authent.setpwd(Pwd);
if(Authent.VerifierCoordonnees()){
%>
<jsp:forward page="Resultat.htmL"/>
<%
}
else{
throw new
Exception(" Ressayez !! login ou mot de passe incorrecte...");
}
}
%>
</body>
</html>
et la servlet :
package servlets;
import java.io.IOException;
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import Beans.Authentification;
/**
* Servlet implementation class Auth
*/
public class Auth extends HttpServlet {
private Connection conn;
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Auth() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
Context ctx;
try {
ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc:mysql://localhost/pfe");
conn = (Connection) ds.getConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @see Servlet#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Authentification At=new Authentification();
if(request.getParameter("Login").equals("")||request.getParameter("Pwd").equals("")){
response.sendRedirect("Erreur.jsp");
}
else{
At.setCnx(conn);
At.setlogin(request.getParameter("Login"));
At.setpwd(request.getParameter("Pwd"));
if(At.VerifierCoordonnees()) response.sendRedirect("Accueil.jsp");
else response.sendRedirect("Erreur.jsp");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
J'ai un projet en J2EE et jessai de recuperer les champs depuis une page html et à laide dune page JSP et une servlet je veux acceder a ma base donnèes mais ça marche po il menvoi directement vers la page derreur je serai vraiment reconaissace si vs pouvez maidè :) voila le code :
page jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page errorPage="Erreur.jsp" %>
<jsp:useBean id="Authent" class="Beans.Authentification"></jsp:useBean>
<!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=ISO-8859-1">
<title>Authentificaion</title>
</head>
<body >
<%
String CodeErreur="";
String Logine=request.getParameter("Login");
String Pwd=request.getParameter("Pwd");
if(Logine=="" || Pwd==""){
throw new Exception("vous avez oublié de précisé votre login ou votre mot de passe!!!");
}
else{
Authent.setlogin(Logine);
Authent.setpwd(Pwd);
if(Authent.VerifierCoordonnees()){
%>
<jsp:forward page="Resultat.htmL"/>
<%
}
else{
throw new
Exception(" Ressayez !! login ou mot de passe incorrecte...");
}
}
%>
</body>
</html>
et la servlet :
package servlets;
import java.io.IOException;
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import Beans.Authentification;
/**
* Servlet implementation class Auth
*/
public class Auth extends HttpServlet {
private Connection conn;
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Auth() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
Context ctx;
try {
ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc:mysql://localhost/pfe");
conn = (Connection) ds.getConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @see Servlet#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Authentification At=new Authentification();
if(request.getParameter("Login").equals("")||request.getParameter("Pwd").equals("")){
response.sendRedirect("Erreur.jsp");
}
else{
At.setCnx(conn);
At.setlogin(request.getParameter("Login"));
At.setpwd(request.getParameter("Pwd"));
if(At.VerifierCoordonnees()) response.sendRedirect("Accueil.jsp");
else response.sendRedirect("Erreur.jsp");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
A voir également:
- Acces à mysql (servlet+jsp) sous eclipse
- Eclipse java - Télécharger - Langages
- Acces rapide - Guide
- Je n'ai plus acces a ma boite mail gmail - Guide
- Accès refusé - Guide
- Trousseau d'accès iphone - Guide