Tomcat gives 404 when I call my servlet

I cannot access my servlet, which I am calling using the form. I checked arborescence, web.xml and the form, but I don't see any problem. I am using Eclipse with a "web dynamic project".

There is my arborescence:

enter image description here

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Z-ProjetJ2EE</display-name>
<welcome-file-list>
  <welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
  <description></description>
  <servlet-name>CommandeServlet</servlet-name>
  <servlet-class>controleur.CommandeServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>CommandeServlet</servlet-name>
  <url-pattern>/urlCommandeServ</url-pattern>
</servlet-mapping>
</web-app>

My form (I tried the full url but it didn't work):

<form action="/urlCommandeServ" method="post">

And my servlet:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String cat = request.getParameter("categorie");
    Float prix = Float.parseFloat(request.getParameter("prix"));
    response.sendRedirect("CreerCommande?cat=" + cat+"&prix="+prix);

I had no errors in eclipse and the log folder in tomcat is empty. could you help me?

EDIT:

There is my mistake:

Error 404

I agree to the answers about my error on response.sendRedirect, but this is not the real subject of my error :) Even if I delete all my code on doPost, I have this error, and not on the white page.

+5
source share
4 answers

<form> html

<form action="urlCommandeServ" method="post">

/urlCommandeServ, Tomcat ( -) - urlCommandeServ, , , , 404.

+3

.jsp.

response.sendRedirect("CreerCommande.jsp?cat=" + cat+"&prix="+prix);

:

response.sendRedirect("CreerCommande?cat=" + cat+"&prix="+prix);

URL- .

<form action="<%=request.getContextPath()%>/urlCommandeServ" method="post">
+4

RequestDispatcher?

RequestDispatcher dispatcher = request.getRequestDispatcher("yourPage.jsp");
if (dispatcher != null){
    dispatcher.forward(request, response);
}
0

: SO

" J2SE, , JAR, - com.mysql.jdbc.Driver( JDBC). JAR Tomcat. mysql-jdbc.jar /WEB -INF/lib ."

0

All Articles