我用表单提交一个变量  然后用Servlet再返回值 但是总是在提交表单的时候出错 404错误部署Servlet应该都注意什么  为什么我总是错呢~  而且又找不到错误!  
工程名为test
我的代码是:
=============================================
srvlet_1.jsp文件:放在test项目根目录下
<%@ page contentType="text/html; charset=utf-8" language="java"  errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Servlet—1</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="/zhuce">
  姓名:<input type="text" name="name" id="textfield" /> <input type="submit" name="button" id="button" value="提交" />
</form>
</body>
</html>
==========================================================================
servlet.java文件:放在test\WEB-INF\src\servlet下 编译成功后放在test\WEB-INF\classes\servlet下
package servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class servlet_11 extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html;charset=GB2312");
PrintWriter out=response.getWriter();
request.setCharacterEncoding("GB2312");
String name=request.getParameter("name");
out.print("<html><head><title>Servlet的简单应用!</title></head>\n");
out.print("<body><h2><center>");
out.print("姓名:"+name);
                               out.print("</center></h2><body></html>");

}
}
========================================
web.xml文件:
添加了
<servlet> 
<servlet-name>cui</servlet-name>
<servlet-class>servlet.servlet_11</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>cui</servlet-name> 
<url-pattern>/zhuce</url-pattern> 
</servlet-mapping>然后就是不能运行  出错  谁帮我找找错误呀~~  

解决方案 »

  1.   

    <form id="form1" name="form1" method="post" action="/zhuce">去掉/试试
      

  2.   

    method="post" 
    在servlet里post加了吗?还是只加了doget
      

  3.   

    <form id="form1" name="form1" method="post" action="/工程名/zhuce"> 
    404这种错误需要注意地址栏的变化和大小写问题
      

  4.   

    <%@ page contentType="text/html; charset=utf-8" language="java"  errorPage="" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Servlet—1 </title> 
    </head> 
    <body> 
    <form id="form1" name="form1" action="zhuce"> 
      姓名: <input type="text" name="name" id="textfield" /> <input type="submit" name="button" id="button" value="提交" /> 
    </form> 
    </body> 
    </html> 我这里改成这样的就可以了,你可以再试一下。
      

  5.   

    错误一:form里action="/zhuce" 多了个"/"
    错误二:form里method是"post",serlvet里只有doGet方法没有doPost方法
      

  6.   

    <form id="form1" name="form1" method="post" action="/zhuce"> 
    个人认为action的地址错了action的地址应该是zhuce,
    还有没有dopost方法
      

  7.   

    看上去好象是没有错~~!
    你看你的web.xml  里面,看是不是空格的问题
      

  8.   

    <%!String basePath=request.getContextPath();%> 
    <form action="<%=basePath%>/zhuce" method="post"> 
    </form> 绝对路径与相对路径的问题
    可参考以前的讨论
    http://topic.csdn.net/u/20091122/21/0809f147-23ec-4c7c-a563-1c0997ed5807.html
      

  9.   

    public void doGet(HttpServletRequest request,HttpServletResponse response)<form id="form1" name="form1" method="post" action="/zhuce"> 
    用post方法提交 那边用get方法得到参数返回  能读到才怪呢修改一个 改成一样的