olfa92
Messages postés1Date d'inscriptiondimanche 31 décembre 2017StatutMembreDernière intervention31 décembre 2017
-
Modifié le 1 janv. 2018 à 22:38
KX
Messages postés16753Date d'inscriptionsamedi 31 mai 2008StatutModérateurDernière intervention25 novembre 2024
-
1 janv. 2018 à 22:48
Bonjour ,
J'ai un erreur qui est le suivant :
type Rapport d''état
message La méthode HTTP GET n''est pas supportée par cette URL
description La méthode HTTP spécifiée n''est pas autorisée pour la ressource demandée. je sais pas ça à cause de quoi voila mon code :
index.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Add New Fruit</h1>
<form method="post" action="ajouterServlet">
<table>
<tr><td>Id:</td><td><input type="text" name="id"/></td></tr>
<tr><td>Nom:</td><td><input type="text" name="nom"/></td></tr>
<tr><td>Quantity:</td><td><input type="text" name="quantity"/></td></tr>
<tr><td>Couleur:</td><td><input type="text" name="couleur"/></td></tr>
<tr><td colspan="2"><input type="submit" value="inserer "/></td></tr>
</table>
</form>
<br/>
<a href="afficheServlet">view fruit</a>
</body>
</html>
ajouterServlet.java
/** To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Servlet;
import dao.Fruit;
import dao.FruitDAO;
import dao.FruitDAOimpl;
import java.io.IOException;
import java.io.PrintWriter;
import static java.lang.System.out;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author dell
*/
@WebServlet(name = "ajouterServlet", urlPatterns = {"/ajouterServlet"})
public class ajouterServlet extends HttpServlet {
/**
* Processes requests for both HTTP GET and POST
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html");
try (PrintWriter out = response.getWriter()) {
Integer qe =Integer.parseInt(request.getParameter("id"));
String n =request.getParameter("nom");
Double q =Double.parseDouble(request.getParameter("quantity"));
String c =request.getParameter("couleur");
Fruit f = new Fruit();
f.setId(qe);
f.setNom(n);
f.setQuantity(q);
f.setCouleur(c);
FruitDAO des =new FruitDAOimpl();
des.ajouterFruit(f);
System.out.println("insertion terminé");
request.getRequestDispatcher("index.html").forward(request, response);
}
}
}
FruitDAOimpl.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dao;
import java.beans.Statement;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author dell
*/
public class FruitDAOimpl implements FruitDAO {
private final Connection con=MaCon.GetConnection();
@Override
public void ajouterFruit(Fruit f) {
String req="INSERT INTO fruit(id,nom,quantity,couleur)"
+ "VALUES('"
+f.getId()+"','"
+f.getNom()+"','"
+f.getQuantity()+"','"
+f.getCouleur()+"','"
+"')";
try {
con.createStatement().executeUpdate(req);
} catch (SQLException ex) {
Logger.getLogger(FruitDAOimpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public List<Fruit> getAllFruit(){
List<Fruit> list=new ArrayList<>();
try{
PreparedStatement ps=con.prepareStatement("select * from fruit");
ResultSet rs=ps.executeQuery();
while(rs.next()){
Fruit e=new Fruit();
e.setId(rs.getInt(1));
e.setNom(rs.getString(2));
e.setQuantity(rs.getDouble(3));
e.setCouleur(rs.getString(4));
list.add(e);
}
con.close();
}catch(SQLException e){e.printStackTrace();}
return list;
}
}
afficheServlet .java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Servlet;
import dao.Fruit;
import dao.FruitDAO;
import dao.FruitDAOimpl;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author dell
*/
@WebServlet(name = "afficheServlet", urlPatterns = {"/afficheServlet"})
public class afficheServlet extends HttpServlet {
/**
* Processes requests for both HTTP GET and POST
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
try (PrintWriter out = response.getWriter()) {
out.println("<a href='index.jsp'>Add New Employee</a>");
out.println("<h1>Employees List</h1>");
FruitDAO dao =new FruitDAOimpl();
List<Fruit> list = null;
try {
list = dao.getAllFruit();
} catch (Exception ex) {
Logger.getLogger(afficheServlet.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.print("<table border='1' width='100%'");
System.out.print("<tr><th>Id</th><th>Name</th><th>Prenom</th><th>Email</th><th>Edit</th><th>Delete</th></tr>");
for(Fruit f:list){
System.out.println("<tr><td>"+f.getNom()+"</td><td>"+f.getQuantity()+"</td><td>"+f.getCouleur()+"</td><td><a href='EditServlet?id="+f.getId()+"'>edit</a></td><td><a href='DeleteServlet?id="+f.getId()+"'>delete</a></td></tr>");
}
out.print("</table>");
}
}}
En espérant que mon erreur sera résolu je vous remercie
A voir également:
La méthode http get n'est pas supportée par cette url