I can't access to my servlet i call with a form. I checked the arborescence, web.xml and the form, but i can't see any problem. I use Eclipse with a "web dynamic project".
There is my arborescence :
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 complete url, but it didn't works) :
<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 didn't have any error in eclipse, and the log folder in tomcat is empty. Could you help me ?
EDIT:
There is my error :
I agree for responses about my error on response.sendRedirect, but this is not the real subject of my error :) Even if i erase all of my code on doPost, i have this error, instead of a white page.
This error indicates that the server could not find the desired resource. This resource can be any file such as JSP, HTML, or image resource. Usually, the resource is present, but it is referenced incorrectly. In most cases, you can fix this by correcting the URL.
The simplest and easiest way to fix your 404 error code is to redirect the page to another one. You can perform this task using a 301 redirect. What's 301, you may ask? It's a redirect response code that signals a browser that the content has been transferred to another URL.
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. This error means the server could not find the requested resource (JSP, HTML, images…) and returns HTTP status code 404. Most of the time, you can fix this error by correcting the URL.
You need to include .jsp
when performing the redirect.
response.sendRedirect("CreerCommande.jsp?cat=" + cat+"&prix="+prix);
instead of:
response.sendRedirect("CreerCommande?cat=" + cat+"&prix="+prix);
Also add your contextpath to the url in the form.
<form action="<%=request.getContextPath()%>/urlCommandeServ" method="post">
Change your <form>
html to
<form action="urlCommandeServ" method="post">
When you're posting to /urlCommandeServ
you're asking Tomcat (or your web server) to look for a web application named urlCommandeServ
which isn't there and hence you get a 404.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With