开发者

HTTP 400 and 500 error messages

when I run my application, I'm having a HTTP error:

HTTP Status 404 - /ProjectName/

This is the URL of my project:

localhost:8080/Initiation1/

When I type this string to the address bar:

localhost:8080/Initiation1/CarteIdentite

, I'm having this HTTP 500 error message:

javax.servlet.ServletException: Error instantiating servlet class ca.web.CarteIdentite
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valve开发者_如何学编程s.AccessLogValve.invoke(AccessLogValve.java:929)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)


root cause 

java.lang.ClassNotFoundException: ca.web.CarteIdentite
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

This is my servlet code:

package ca.web;

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;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;

/**
 * Servlet implementation class CarteIdentite
 */
@WebServlet("/CarteIdentite")
public class CarteIdentite extends HttpServlet
{
    // paramètres d’instance
    private String defaultNom = null;
    private String defaultAge = null;
    private String defaultCourriel = null;
    //init
    public void init()
    {
    // on récupère les paramètres d’initialisation de la servlet
    ServletConfig config = getServletConfig();
    defaultNom = config.getInitParameter("defaultNom");
        if(defaultNom==null)
        {
            defaultNom="XXXXXXXXXXXXXXXX";
        }
        defaultAge = config.getInitParameter("defaultAge");
        if(defaultAge==null)
        {
            defaultAge="AAA";
        }
        defaultCourriel = config.getInitParameter("defaultCourriel");
        if(defaultCourriel==null)
        {
            defaultCourriel="XXXXXX@XXXXXXXX.XX";
        }
    }
    //GET
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
    IOException, ServletException
    {
    // on récupère les paramètres du formulaire

    String nom = request.getParameter("txtNom");
    if (nom == null)
    {
        nom = defaultNom;
    }
    String age = request.getParameter("txtAge");
    if (age == null)
    {
        age = defaultAge;
    }
    String courriel = request.getParameter("txtCourriel");
    if (courriel == null)
    {
        courriel = defaultCourriel;
    }
    // on affiche le formulaire
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    out.println
    (
        "<html>"+
        "<head>"+
        "<title>Carte d’identité</title>"+
        "</head>"+
        "<body>"+
        "<center>"+
        "<h2>Carte d’identité</h2>"+
        "<form action=’’ method=’post’>"+
        "<table>"+
        "<tr>"+
        "<td>Nom:</td>"+
        "<td><input name=’txtNom’ value=’"+nom+"’ type=’text’ size=’30’></td>"+
        "</tr>"+
        "<tr>"+
        "<td>Age:</td>"+
        "<td><input name=’txtAge’ value=’"+ age +"’ type=’text’ size=’3’></td>"+
        "</tr>"+
        "<tr>"+
        "<td>Courriel:</td>"+
        "<td><input name=’txtCourriel’ value=’"+courriel+"’ type=’text’ size=’30’></td>"+
        "</tr>"+
        "</table>"+
        "<table>"+
        "<tr>"+
        "<td><input type=’submit’ value=’Envoyer’></td>"+
        "<td><input type=’reset’ value=’Effacer’></td>"+
        "</tr>"+
        "</table>"+
        "</form>"+
        "</center>"+
        "</body>"+
        "</html>"       
    );
    }
    /**
    * @param request la requête HTTP du client
    * @param response la réponse HTTP qu’on va construire
    */
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
    //on passe la main au GET
    doGet(request, response);
    }
}

This is my web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app SYSTEM "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <servlet>
        <servlet-name>CarteIdentite</servlet-name>
        <servlet-class>ca.web.CarteIdentite</servlet-class>
            <init-param>
            <param-name>defaultNom</param-name>
            <param-value>inconnu</param-value>
            </init-param>
            <init-param>
            <param-name>defaultAge</param-name>
            <param-value>XXX</param-value>
            </init-param>
            <init-param>
            <param-name>defaultCourriel</param-name>
            <param-value>inconnu</param-value>
            </init-param>
        </servlet>
        <servlet-mapping>
        <servlet-name>CarteIdentite</servlet-name>
        <url-pattern>/CarteIdentite</url-pattern>
    </servlet-mapping>
</web-app>

Here is my project structure:

HTTP 400 and 500 error messages


Maybe Eclipse isn't treating src as a source folder. Try right clicking on it and choosing Build Path -> Use as source folder.


Check if the class ca.web.CarteIdentite has compiled correctly and made way into the WAR of your project (under WEB-INF/classes). If not, check/correct the project buildpath settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜