how can i send a parameter to server-side for Jsp?

how can i send a parameter to server-side for Jsp?

maye100maye100 Posts: 2Questions: 0Answers: 0
edited October 2011 in General
i want send a parameter(date) to server-side,like this:
[code]
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "HaiDeBao.jsp?viewDate='2011-10-03'",//fail
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
},
[/code]
and Jsp page how do it ?
How to send parameters
how to receive parameters?

i am chinese and my english is poor,who can help me?thank you very much

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited October 2011
    maye100,

    I think it's simply a matter of your formatting. You have single quotation marks (') around your date, which are reserved characters in URIs. If your application is handling them correctly, that's good. Otherwise, it's safer to use something like:

    HaiDeBau.jsp?viewdate=2011-10-03

    --

    Additional thoughts: are you SURE it's the URL that's failing? Maybe the resource is found, but it is not returning valid JSON?

    --

    Interesting side-note: the way we are receiving URLs to our Servlets, we need an extra slash. So when we call to a Servlet, we format it as:

    MyServlet/?parameter=foo

    I don't think this is your problem; our web server handles requests for JSPs in the expected way. But I wanted to mention it "just in case".
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited October 2011
    If your jsp is only looking at the POST vars, then adding your paramater to the urlstring might fail

    In fnServerData, aoData is an array of objects representing name/value pairs - these will be formatted as your querystring/postdata in the .ajax() call. You can add your param to this list and the it will be sent with the .ajax call (which you are calling with POST) to your server.

    [code]

    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "HaiDeBao.jsp",
    "fnServerData": function ( sSource, aoData, fnCallback ) {

    aoData.push({ name: "viewDate", value: "2011-10-03" }); // add param to aoData

    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    },

    [/code]
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Nicely spotted. Could very well be the POST vs. GET part of the equation.
This discussion has been closed.