[英]Tomcat gives 404 when i call my servlet
I can't access to my servlet i call with a form. 我无法使用表单访问我的servlet。 I checked the arborescence, web.xml and the form, but i can't see any problem.
我检查了arborescence,web.xml和表单,但我看不出任何问题。 I use Eclipse with a "web dynamic project".
我使用Eclipse和“web动态项目”。
There is my arborescence : 有我的树枝:
My web.xml : 我的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 : 而我的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. 我在eclipse中没有任何错误,tomcat中的日志文件夹是空的。 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. 我同意关于我在response.sendRedirect上的错误的回复,但这不是我的错误的真正主题:)即使我删除了doPost上的所有代码,我有这个错误,而不是白页。
You need to include .jsp
when performing the redirect. 执行重定向时,您需要包含
.jsp
。
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. 还要将您的contextpath添加到表单中的url。
<form action="<%=request.getContextPath()%>/urlCommandeServ" method="post">
Change your <form>
html to 将
<form>
html更改为
<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. 当您发布到
/urlCommandeServ
您要求Tomcat(或您的Web服务器)查找名为urlCommandeServ
的Web应用程序,该应用程序不存在,因此您将获得404。
Why don't you use RequestDispatcher? 你为什么不使用RequestDispatcher?
RequestDispatcher dispatcher = request.getRequestDispatcher("yourPage.jsp");
if (dispatcher != null){
dispatcher.forward(request, response);
}
"If this code works in your J2SE it means you need to have a JAR file somewhere containing com.mysql.jdbc.Driver class (so called JDBC driver). This JAR needs to be visible in Tomcat. So, I would suggest to place mysql-jdbc.jar at physical location to /WEB-INF/lib directory of your project." “如果这个代码在你的J2SE中工作,那就意味着你需要在某个地方包含一个包含com.mysql.jdbc.Driver类的JAR文件(所谓的JDBC驱动程序)。这个JAR需要在Tomcat中可见。所以,我建议放置物理位置的mysql-jdbc.jar到项目的/ WEB-INF / lib目录。“
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.