IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

Erreur java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:8080/tetris/requ


Sujet :

Servlets/JSP Java

  1. #1
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut Erreur java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:8080/tetris/requ
    Bonsoir à tous,j'ai une erreur sur eclipse qui est erreur java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:8080/tetris/requete
    j'ai en effet vérifier ma conf et ne trouve pas d'ou cela vient ,je dois me connecter à une base de donnée pour chercher des score pour mon tetris la connexion à la base est ok mais quand j'appelle ma fonction pour me connecter a la servlet il me m'est une erreur 405 aidez moi s'il vouplaît,voici ma conf et l'arborescence de mes fichiers.

    arborescence:Nom : Capture.PNG
Affichages : 1402
Taille : 11,8 Ko

    mon fichier web.xml:
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <?xml version="1.0" encoding="ISO-8859-1"?>
     
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
        <display-name>Mes servlets</display-name>
        <description>
          Premieres servlets
        </description>
    	<servlet>
    	<servlet-name>tetris</servlet-name> 
    	<servlet-class>Servlet.Servlet</servlet-class> 
    	<description>Servlet d'essai de la connection BD</description> 
        </servlet>
    <servlet-mapping> 
    	<servlet-name>tetris</servlet-name>
    	<url-pattern>/requete</url-pattern> 
    </servlet-mapping>
    </web-app>

    ma fonction de connexion a la servlet dans la classe PanneauScore:
    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    public void Connect_Servlet() {
    		String res;
    		String nom=txtAaa.getText();
    		try
    		{
    			// Connexion à la servlet
    			URL url=new URL("http://localhost:8080/tetris/requete");
    			URLConnection connexion=url.openConnection();
    			connexion.setDoOutput(true);
    			// Récupération du flux de sortie
    			ObjectOutputStream fluxsortie = new ObjectOutputStream(connexion.getOutputStream());
    			// Envoi du nom à rechercher
    			fluxsortie.writeObject(nom);
    			// Récupération du flux d’entrée
    			ObjectInputStream fluxentree = new ObjectInputStream(connexion.getInputStream());
    			// Récupération du résultat de la requête
    			SerializedResultSet donnees=(SerializedResultSet) fluxentree.readObject();
    			// affichage du résultat
    			donnees.first();
    			Vector contenu=new Vector();
    			contenu.clear();
    			listeResultat.setListData(contenu);
    			for (int i=0; i<donnees.recordCount();i++)
    			{
    				res=donnees.getString("nom")+" "+donnees.getString("score");
    				contenu.addElement(res);
    				donnees.next();
    			}
    			if (donnees.recordCount()==0) 
    				{
    				res="Pas de personne correspondante";
    				contenu.addElement(res);
    				}
    			listeResultat.setListData(contenu);
     
    		}
    		catch (Exception sql)
    		{
    			System.out.println("erreur "+sql);
    		}
     
    	}

    l'endroit ou j'appelle ma fonction de connexion dans l'applet principal tétris:
    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     void BtnScore_actionPerformed(ActionEvent e) {
         PS.Connect_Servlet();
         PS.setModal(true);
         PS.pack();
         PS.show();
      }

    ma servlet appelait servlet:
    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    package Servlet;
     
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
     
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.sql.DataSource;
     
    public class Servlet extends HttpServlet {
     
    	Connection BD;
    	private DataSource ds;
     
    	public void init() throws ServletException {
    		try {
    			Context initCtx = new InitialContext();
    			System.out.println("lookup de env");
    			Context envCtx = (Context) initCtx.lookup("java:comp/env");
    			System.out.println("lookup de tetris");
    			ds=(DataSource) envCtx.lookup("tetris");
     
    		}
    		catch(Exception er) {
    			System.out.println("Erreur de chargement du contexte " + er);
    		}
    	}
     
    	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    			throws ServletException, IOException {
    				try {
    				BD=ds.getConnection();
    				Statement s = BD.createStatement();
    				ResultSet r = s.executeQuery("select * from score");
    //				PrintWriter out=null;
    //				resp.setContentType("text/html");
    //				out = resp.getWriter();
    //				out.println("<html>");
    //				out.println("<head><title> Test servlet </title></head>");
    //				out.println("<body>");
    //				out.println("Contenu de la table personne <BR>");
    //				out.println("<table>");
    //				out.println("<TR>");
    //				out.println("<TD>Nom</TD>");
    //				out.println("<TD>score</TD>");
    //				out.println("</TR>");
    //				while (r.next()) {
    //					out.println("<TR>");
    //					out.println("<TD>");
    //					out.println(r.getString("nom"));
    //					out.println("</TD>");
    //					out.println("<TD>");
    //					out.println(r.getString("score"));
    //					out.println("</TD>");
    //					out.println("</TR>");
    //					}
    //				out.println("</table>");
    //				out.println("</body>");
    //				out.println("</html>");
    				r.close();
    				s.close();
    				BD.close();
    				s = null;
    				r = null;
    			} catch (java.sql.SQLException ex) {
    				System.out.println("Erreur d'exécution de la requête SQL \n"+ex);
    			} 
    		}
    }
    Le code de retour dans la console côté serveur:
    Code DEBUG : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    oct. 09, 2014 8:58:27 PM org.apache.catalina.core.AprLifecycleListener init
    INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_20\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jre1.8.0_20;C:\Windows\System32;C:\Users\kevin\Downloads\adt-bundle-windows-x86_64-20140702\eclipse\sdk\tools;C:\wamp\bin\php\php5.5.12\;.
    oct. 09, 2014 8:58:29 PM org.apache.coyote.AbstractProtocol init
    INFOS: Initializing ProtocolHandler ["http-nio-8080"]
    oct. 09, 2014 8:58:29 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
    INFOS: Using a shared selector for servlet write/read
    oct. 09, 2014 8:58:29 PM org.apache.coyote.AbstractProtocol init
    INFOS: Initializing ProtocolHandler ["ajp-nio-8009"]
    oct. 09, 2014 8:58:29 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
    INFOS: Using a shared selector for servlet write/read
    oct. 09, 2014 8:58:29 PM org.apache.catalina.startup.Catalina load
    INFOS: Initialization processed in 6479 ms
    oct. 09, 2014 8:58:30 PM org.apache.catalina.core.StandardService startInternal
    INFOS: Démarrage du service Catalina
    oct. 09, 2014 8:58:30 PM org.apache.catalina.core.StandardEngine startInternal
    INFOS: Starting Servlet Engine: Apache Tomcat/8.0.9
    oct. 09, 2014 8:58:30 PM org.apache.catalina.startup.HostConfig deployDescriptor
    INFOS: Déploiement du descripteur de configuration C:\serveur\apache-tomcat-8.0.9\conf\Catalina\localhost\ProjetServlet.xml
    oct. 09, 2014 8:58:32 PM org.apache.jasper.servlet.TldScanner scanJars
    INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    oct. 09, 2014 8:58:33 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
    INFOS: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [268] milliseconds.
    oct. 09, 2014 8:58:34 PM org.apache.catalina.startup.HostConfig deployDescriptor
    INFOS: Deployment of configuration descriptor C:\serveur\apache-tomcat-8.0.9\conf\Catalina\localhost\ProjetServlet.xml has finished in 4*117 ms
    oct. 09, 2014 8:58:34 PM org.apache.catalina.startup.HostConfig deployDescriptor
    INFOS: Déploiement du descripteur de configuration C:\serveur\apache-tomcat-8.0.9\conf\Catalina\localhost\tetris.xml
    oct. 09, 2014 8:58:34 PM org.apache.jasper.servlet.TldScanner scanJars
    INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    oct. 09, 2014 8:58:34 PM org.apache.catalina.startup.HostConfig deployDescriptor
    INFOS: Deployment of configuration descriptor C:\serveur\apache-tomcat-8.0.9\conf\Catalina\localhost\tetris.xml has finished in 509 ms
    oct. 09, 2014 8:58:34 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Déploiement du répertoire C:\serveur\apache-tomcat-8.0.9\webapps\docs de l'application web
    oct. 09, 2014 8:58:35 PM org.apache.jasper.servlet.TldScanner scanJars
    INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    oct. 09, 2014 8:58:35 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Deployment of web application directory C:\serveur\apache-tomcat-8.0.9\webapps\docs has finished in 282 ms
    oct. 09, 2014 8:58:35 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Déploiement du répertoire C:\serveur\apache-tomcat-8.0.9\webapps\examples de l'application web
    oct. 09, 2014 8:58:39 PM org.apache.catalina.core.ApplicationContext log
    INFOS: ContextListener: contextInitialized()
    oct. 09, 2014 8:58:39 PM org.apache.catalina.core.ApplicationContext log
    INFOS: SessionListener: contextInitialized()
    oct. 09, 2014 8:58:39 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Deployment of web application directory C:\serveur\apache-tomcat-8.0.9\webapps\examples has finished in 4*779 ms
    oct. 09, 2014 8:58:39 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Déploiement du répertoire C:\serveur\apache-tomcat-8.0.9\webapps\host-manager de l'application web
    oct. 09, 2014 8:58:40 PM org.apache.jasper.servlet.TldScanner scanJars
    INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    oct. 09, 2014 8:58:40 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Deployment of web application directory C:\serveur\apache-tomcat-8.0.9\webapps\host-manager has finished in 346 ms
    oct. 09, 2014 8:58:40 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Déploiement du répertoire C:\serveur\apache-tomcat-8.0.9\webapps\manager de l'application web
    oct. 09, 2014 8:58:40 PM org.apache.jasper.servlet.TldScanner scanJars
    INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    oct. 09, 2014 8:58:40 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Deployment of web application directory C:\serveur\apache-tomcat-8.0.9\webapps\manager has finished in 244 ms
    oct. 09, 2014 8:58:40 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Déploiement du répertoire C:\serveur\apache-tomcat-8.0.9\webapps\ROOT de l'application web
    oct. 09, 2014 8:58:40 PM org.apache.jasper.servlet.TldScanner scanJars
    INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    oct. 09, 2014 8:58:40 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFOS: Deployment of web application directory C:\serveur\apache-tomcat-8.0.9\webapps\ROOT has finished in 245 ms
    oct. 09, 2014 8:58:40 PM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["http-nio-8080"]
    oct. 09, 2014 8:58:40 PM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["ajp-nio-8009"]
    oct. 09, 2014 8:58:40 PM org.apache.catalina.startup.Catalina start
    INFOS: Server startup in 10821 ms
    lookup de env
    lookup de tetris

    N'hésiter pas si il manque quelque chose merci de prendre de votre temps cordialement.

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Dans ton applet tu fais ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    			URL url=new URL("http://localhost:8080/tetris/requete");
    			URLConnection connexion=url.openConnection();
    			connexion.setDoOutput(true);
    autrement dit une commande http POST

    hors ta servlet n'implémente que le doGet, donc le post n'est pas autorisé. Il faut aussi implémenter doPost.

  3. #3
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Merci de votre réponse tchize_
    Pour la servlet, j'avais utiliser le code dans un autre projet et je n'utilisais pas la méthode doPost et cela fonctionnait avec doGet, je vais essayer ce que vous dites je vous tiens au courant merci.

  4. #4
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    j'ai testé et cela fonctionne bien merci pour votre aide .

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 04/06/2010, 11h33
  2. Réponses: 0
    Dernier message: 19/03/2010, 11h13
  3. Server returned HTTP response code: 400 for URL
    Par devroot dans le forum Développement Web en Java
    Réponses: 2
    Dernier message: 21/08/2009, 14h41
  4. Server returned HTTP response code: 500
    Par azerty_123 dans le forum Services Web
    Réponses: 3
    Dernier message: 30/07/2009, 19h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo