0

I want to retrieve the value of a parameter on the requested JSP called with ajax. I pass the data as:

$(document).ready(function(){
    $(".button-links").click(function(){
        var id=this.id;
        $("#result").load("validate.jsp?sem=id");
    });
});

Now I want to retrieve the data stored in the variable sem in the requested JSP file validate.jsp.

guido
  • 18,864
  • 6
  • 70
  • 95
kunal18
  • 1,935
  • 5
  • 33
  • 58
  • Where in file you want to use the `sem` variable? – Ajinkya Jun 16 '12 at 15:23
  • Here "sem" will store the 'id' of the button clicked by the user. I want to know the id to carry out the further process. – kunal18 Jun 16 '12 at 15:26
  • Can you tell some details like what you wamt to do with `sem` ? Like displaying `sem` in textbox etc? – Ajinkya Jun 16 '12 at 15:29
  • I want to retrieve the value of 'sem' and display the button-specific information on the requested page i.e, 'validate.jsp'. Data stored by 'sem' is for internal usage. – kunal18 Jun 16 '12 at 15:34
  • Possible duplicate [question](http://stackoverflow.com/questions/1890438/how-to-get-parameters-from-the-url-with-jsp) – Ravi Kadaboina Jun 16 '12 at 15:40
  • @Ravi: OP knows the value of `sem` as he only setting that value. He wants to use that value in content loaded via Ajax. IMHO both are different questions. – Ajinkya Jun 16 '12 at 15:45

2 Answers2

0

Still I am not sure what exactly you want to do with value of sem.
Taking a scenario. You want to capture clicked buttons value in sem and want to display it inside a input present in validate.jsp.

$(document).ready(function(){
    var id = null;
    $(".button-links").click(function(){
        id=this.id;
        $("#result").load("validate.jsp?sem=id");
        // Assumng we have a hidden input with class="buttoName"
        $("#result .buttonName").val(id);
    });

    // Use on as validate.jsp is dynamically loaded via Ajax
    $(".submitInValidate").on('click',function(){
       var requierdVal =  $("#result .buttonName").val();  
       // Now you can do further processing with this value. 
    });

});

By this way you can get value of id or sem in validate.jsp.
If you looking for something else just set the value of sem to hidden input and use it later in validate.jsp.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
  • Thanx for reply! As you told you could not understand what exactly I want to do, so let me clear it: "I have a web page having 5 buttons(changed there looknfeel so that they could look like links :) ), each button holds the text value- Exam result for semester 1, Exam result for semester 2, Exam result for semester 3,.. so on. – kunal18 Jun 16 '12 at 15:59
  • I have put all these buttons buttons under the same class and whenever user clicks on a button all these buttons disappear and validate.jsp is loaded using ajax asking for name, rollno, etc. Now I have assigned each button an id=semester so I want to retrieve the semester of the student from variable 'sem' and use it for searching in specific table in database when he clicks on submit button on validate.jsp page." – kunal18 Jun 16 '12 at 15:59
  • I want to retrieve the value of 'sem' inside validate.jsp – kunal18 Jun 16 '12 at 16:00
  • @StalinSubramaniam: So as I mentioned you can assign that value to hidden input field and can use the same when user clicks on submit button in validate.jsp. – Ajinkya Jun 16 '12 at 16:05
  • $(".submitInValidate").on('click',function(){ var requierdVal = $("#result .buttonName").val(); // Now you can do further processing with this value. }); This is not working! Actually I have defined an onclick event on submit button for validation of input fields on validate.jsp – kunal18 Jun 17 '12 at 05:09
0

Please try this code:

javascript:

$(document).ready(function(){
    $(".button-links").click(function(){
        var id=this.id;

        $.ajax({
            url:"validate.jsp?sem="+id,
            type: 'POST',
            success: function(response) {
                alert(response);
            }
        });
    });
});

validate.jsp

<%
    String sem = request.getParameter( "sem" );
    System.out.println( "Printed:" + sem );
%>
Bunlong
  • 652
  • 1
  • 9
  • 21