0

I am calling a JSP page in Jquery as

                onExpandRow: function(index,row){                    
                    height:160,  
                    border:true,  
                    cache:true,                          
                    href:'service.jsp?empNo='+empNo,  

and in service.jsp I would like to pass the parameter to a servlet and return data in JSON.

JSP code snippet

   $(document).ready(function(){
$.ajax({ url: "service.jsp",
        context: document.body,
        success: function(){
           $.get('myservlet?empNo=<%=request.getParameter("empNo")%>',
        function(data) {

For some reason this is not working, however if I am directly calling service.jsp?empNp=JAMES, then it works as I expect.

How and what is the best way to get values from servlet when I am calling service.jsp when I am clicking a row in Jquery? Ideally I would like to call service.jsp, as soon as service.jsp is called, would like to invoke servlet and return data and display the results.

Any help is highly appreciable.

2
  • in the jsp code snippet, why are you calling an ajax to the same page, and not directly calling myservlet ? Commented Apr 17, 2013 at 16:57
  • @DanyY The reason why I am calling the same page is to submit when I am calling jsp. Commented Apr 17, 2013 at 17:21

1 Answer 1

1

I hope i understood correctly, but to answer your last question . Here is my though :

Step 1 : in JSP you store the value of the parameter in a hidden field

<input type="hidden" id="empNo" value="<%=request.getParameter("empNo")%>" />

Step 2 : You make an ajax call to myservlet on document.ready :

 $(document).ready(function(){
$.ajax({ url: "myservlet",
        data : {empNo : $('#empNo')}
        success: function(data){
//handle the result returned in data          
        }
       }
   }
Sign up to request clarification or add additional context in comments.

3 Comments

Dany When I am calling service.jsp when I am expanding a row, call is not going to servlet. How can I call the servlet when call is being made to service.jsp?
It might be that document.ready is not beign called if you're not loading a new page.I'm thinking of smthg, why don't you call myservlet on the action to expand the row, and on success you open service.jsp.
Dany, issue has been resolved, there was a problem in my code which stopped calling $(document).ready(function(){. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.