With this request

$('#add_author').submit(function(){ $.ajax({ type: "POST", url: "/addauthor", data: $("#author_name").val(), success: function(html){ $("#content").html(html); } }); return false; }); 

I appeal to such a servlet

  public class AddAuthorServlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String authorName = request.toString(); //String authorName = request.getParameter("genre-name"); SocketConnection.output.println("add_genre " + authorName); //String string = SocketConnection.input.readLine(); RequestDispatcher rs = request.getRequestDispatcher("workshop.html"); rs.forward(request, response); } } 

Trying to pass the value of author_name , the servlet does not receive anything. How correctly to transfer by means of ajax inquiry this servlet 'value and at correctly to receive it?

    1 answer 1

     public void service(HttpServletRequest request, HttpServletResponse response) 

    Where in your request is the call to this method?

    The server is looking for a function "addauthor"

    • I.e? The request refers to url /addauthor , and this mapping is the servlet. Or do I misunderstand you? - will_hunting
    • It is logical to assume that the structure of the call to the servlet is: AddAuthor / service - Alexsandr Ter
    • It does not help, because a servlet is registered in web.xml, it will not see it, it will be addressed as AddAuthor/service <servlet> <servlet-name> AddAuthor </ servlet-name> <servlet-class> AddAuthorServlet </ servlet-class > </ servlet> <servlet-mapping> <servlet-name> AddAuthor </ servlet-name> <url-pattern> / addauthor </ url-pattern> </ servlet-mapping> - will_hunting
    • Well, does he call this function at all? Try setting breakpoit at the beginning of the function - Alexsandr Ter