You are mapping your AddComment request to be /servlets/AddComment but
making AJAX request to "AddComment".

Probably changing $.post to this will help:

$.post("/servlets/AddComment", function(data){

Unless the current page is also in /servlets.

PS. You might find $.getJSON() method useful
(http://docs.jquery.com/Ajax/jQuery.getJSON).

----
Read jQuery HowTo Resource  -  http://jquery-howto.blogspot.com



2009/3/23 Michael <lifeng_c...@126.com>:
>
> It takes me almost half a day , but I haven't solve it ,I don't know
> why .
> I would be much appreciate for your help...
>
> $(document).ready(function(){
>
>    alert("can show");
>
>    $("#button").click(function(){
>
>        alert("when click button , can show ");
>
>        $.post("AddComment",null,function(data){                //
> AddComment is a servlet name
>
>                        alert("here can't show");
>
>        },"json");
>    });
> });
>
> servlet ,root ,"servlets/AddComment",
>
> public void doPost(HttpServletRequest request, HttpServletResponse
> response)
>            throws ServletException, IOException {
>
>            System.out.println("here can't show,that is ,the method
> $.post  does not work");
> }
>
> servlet config in web.xml:
>  <servlet>
>    <servlet-name>AddComment</servlet-name>
>    <servlet-class>servlets.AddComment</servlet-class>
>    <load-on-startup>1</load-on-startup>
>  </servlet>
>  <servlet-mapping>
>    <servlet-name>AddComment</servlet-name>
>    <url-pattern>/servlets/AddComment</url-pattern>
>  </servlet-mapping>
>

Reply via email to