ошибка 404 Связь сервлета / JSP в форме - PullRequest
0 голосов
/ 20 мая 2018

Я пытаюсь создать простую форму с именем и паролем.Но когда я нажимаю кнопку подтверждения в моей форме, называемой «надпись», я получаю сообщение об ошибке 404. Моя ошибка: ETAT 404 HTTP- / тип надписи: сообщение о взаимопонимании: / описание надписи: ресурс недоступен Это все, что у меня есть.

Вместо этого я должен получить пустую страницу, потому что в моем методе записи ничего нет.

Вот мой NEW файл JSP inscription.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!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>Inscription</title>
    <link type="text/css" rel="stylesheet" href="<c:url value="/inc/style.css"/>" />
</head>
<body>
<form method="post" action="/inscription">
            <fieldset>
                <legend>Inscription</legend>
                <p>Vous pouvez vous inscrire via ce formulaire.</p>

                <label for="email">Adresse email <span class="requis">*</span></label>
                <input type="text" id="email" name="email" value="" size="20" maxlength="60" />
                <br />

                <label for="motdepasse">Mot de passe <span class="requis">*</span></label>
                <input type="password" id="motdepasse" name="motdepasse" value="" size="20" maxlength="20" />
                <br />

                <label for="confirmation">Confirmation du mot de passe <span class="requis">*</span></label>
                <input type="password" id="confirmation" name="confirmation" value="" size="20" maxlength="20" />
                <br />

                <label for="nom">Nom d'utilisateur</label>
                <input type="text" id="nom" name="nom" value="" size="20" maxlength="20" />
                <br />

                <input type="submit" value="Inscription" class="sansLabel" />
                <br />
            </fieldset>
        </form>
</body>
</html>

Вот мой НОВЫЙ сервлет Inscription.java:

package com.sdzee.pro.servlets;

import java.io.IOException;

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 Inscription
 */
@WebServlet( "/inscription" )
public class Inscription extends HttpServlet {
    private static final long  serialVersionUID = 1L;
    public static final String VUE              = "/WEB-INF/inscription.jsp";

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Inscription() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append( "Served at: " ).append( request.getContextPath() );
        this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    public void doPost( HttpServletRequest request, HttpServletResponse response )
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet( request, response );
    }

}

А вот мой web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
    <servlet>
        <servlet-name>Inscription</servlet-name>
        <servlet-class>com.sdzee.pro.servlets.Inscription</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Inscription</servlet-name>
        <url-pattern>/inscription</url-pattern>
    </servlet-mapping>
</web-app>

1 Ответ

0 голосов
/ 20 мая 2018

ошибка 404 означает, что ресурс, к которому вы пытаетесь получить доступ, не найден.Так что это проблема с вашим отображением URL для вашего сервлета.

<form method="post" action="<c:url value="/inscription"/>">

Это неверно, вам нужно экранировать такие кавычки:

<form method="post" action="<c:url value=\"inscription\">">

Но если вы знаете свое отображение URLпочему бы просто не жестко закодировать его с относительным путем?(«..» предназначен для перехода в каталог)

<form method="post" action="../inscription">

РЕДАКТИРОВАТЬ:

Только что заметил несоответствие с вашим отображением URL ...

в вашем web.xml это:

 <url-pattern>/inscription</url-pattern>

Но у вас есть аннотация сервлета как:

@WebServlet( "/Inscription" )

Это также принесет вам проблемы.Убедитесь, что они одинаковы.Измените аннотацию, чтобы она соответствовала вашему отображению сервлета web.xml:

@WebServlet( "/inscription" )

Отображение URL сервлета чувствительно к регистру.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...