Servlet

maxi - Modifié le 8 avril 2020 à 21:58
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 - 11 avril 2020 à 19:14
Bonjour, je debite avec je jsp mais je n arrive pas avance je suis bloque au niveau de l ereur 404 je ne sais pas ce qui bloque





package com.servlet.login;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
  • Servlet implementation class Login
  • /

@WebServlet("/login")
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
  • @see HttpServlet#HttpServlet()
  • /

public Login() {
super();
// TODO Auto-generated constructor stub
}

/**
  • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  • /

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

this.getServletContext().getRequestDispatcher( "/Login.jsp" ).forward( request, response );

}

/**
  • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  • /

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

}



<?xml version="1.0" encoding="UTF-8"?>
<select>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
<display-name>HelloWord</display-name>

<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>com.servlet.login.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

<error-page>
<error-code>404</error-code>
<location>/error/404.java</location>
</error-page>
</web-app>
</select>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p>hello</p>
</body>
</html>

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 127
11 avril 2020 à 19:14
Bonjour,

Il faut choisir, soit tu utilises le fichier web.xml, soit tu utilises l'annotation @WebServlet.
Si tu débutes, je te conseille plutôt le web.xml, car il y a davantage de documentation sur internet puisque c'est beaucoup plus ancien.

À vue de nez, je ne vois pas d'autres erreurs, mais si tu ne t'en sors pas je t'invites à partir d'un projet existant et le modifier pas à pas.
Exemple : https://codes-sources.commentcamarche.net/source/100195-exemple-simple-d-application-jstl
0
Rejoignez-nous