error :404 not found with jquery and servlet

error :404 not found with jquery and servlet

我想将数据从 html 页面发送到 servlet,我使用 jquery 和一个 post 请求,错误是:加载资源失败:服务器响应状态为 404(未找到),我试图更改 post 请求中的 url,但我遇到了同样的错误。

index.html

 <body>
    <form id="form">
      <p><input type="text"  id="name"></p> 
       <p> <input type="button" value="test servlet" id="test"  ></p>  
        <div id="res"></div> 
    </form></body>

test.js

 $("#test").click(function (){
var n = $("#name").val();    
   $.post("controller/Test.java",{name:n},function(data){

         $("#res").html(data);
   }); 

包:控制器,Test.java

  protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
    PrintWriter out = response.getWriter();
   String a ;
a = request.getParameter("name");

 out.println("welcome" +a);
}

谢谢

这是完全错误的

$.post("controller/Test.java",{name:n},function(data){

Servlet 必须首先映射到 URL 路径,传统上这是通过 web.xml.

完成的

我建议你重温 java servlet 基础:http://docs.oracle.com/javaee/5/tutorial/doc/bnafd.html