Ajax Post请求到Servlet?

Hi I have been trying to pass value from ajax to servlet ,have used JQUERY jquery-1.3.2 & query-1.3.2.min .I am successfully able to send the data but if i print the value in servlet getting null

Here is my js event

    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="js/myjquery.js"></script>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" >


    function AddNext(event)
    {
       MQA.EventManager.addListener(map, 'click', AddNext);
        var lata = event.ll.getLatitude();
        var lnga = event.ll.getLongitude();

        var latlon=lata+"|"+lnga;
        addpasslatlon(latlon);
        MQA.EventManager.clearAllListeners( map);
        exit();
      };   

myjquery.js-

    function addpasslatlon(latlon) 
    {           
           var value=latlon;
           $.ajax({
             url:'insertPos',
             type:'POST',
             data:value,
             success : function(data){
                 alert('success'+data);
             }
           });
    }

MY servlet class-

    public class InsertPos extends HttpServlet {
        private static final long serialVersionUID = 1L;


        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();

            String a =request.getParameter("value");
            System.out.println(a);
        }

    }

web.xml-

    <url-pattern>/insertPos</url-pattern>

O/P- null

You have to send an object in data:

data:{value : value},
//----^^^^^-------------this is the key which you refered in your servlet.

and at your backend you should get it with key value as you are currently doing.

You should run a simple test that allows you to see what parameters you have available, you can use getParameterMap() which returns a Map object:

System.out.println(request.getParameterMap());

this will print out all available parameters for you with key, value pairs of the map, so next when you know all your keys in the map and which values they map to, you can invoke it like you already tried, however this time you will be confident that the value already exists as part of the parameters:

request.getParameter("<insertKeyHere>");

What Jai did is that he showed you how to pass JSON object to the servlet

data:{value : value},

This is great for the servlet as it can easily resolve it to a parameter map.

The problem with this is that you dont want to declare an entire JSON string your self... its fine for one or two values but definitely not for bigger objects.

What you might want to use is the javascript function that converts all objects to JSON, you could of added this to your ajax call, and it would of worked:

data: JSON.stringify(value),