0

i want to send data from html page to the servlet, i use jquery and a post request, the error is :Failed to load resource: the server responded with a status of 404 (Not Found),i tried to change the url in the post request but i had the same error.

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);
   }); 

package:controller,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);
}

thanks

mass_develop
  • 43
  • 1
  • 7

1 Answers1

0

This is completely wrong

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

Servlets has to be mapped first into URL path, traditionally this is done via web.xml.

I suggest you revisit java servlet basic: http://docs.oracle.com/javaee/5/tutorial/doc/bnafd.html

gerrytan
  • 40,313
  • 9
  • 84
  • 99