Results 1 to 4 of 4
  1. #1
    anny123 is offline Member
    Join Date
    Nov 2011
    Posts
    9
    Rep Power
    0

    Default can we get the control back to the jsp page after displaying data through servlet ?

    I am displaying the data(String Array) through the servlet . Now I want to pass the same string array tojsp page.


    I tried to pass with Session.setAttribute and in get the array with session.getAttribute in jsp as well as with response.setAttibute and response.getAttribute in jsp but was not successful.

    can anyone guide me pls.

    Thanks

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default Re: can we get the control back to the jsp page after displaying data through servlet

    Can we have a look in your code?
    Swastik

  3. #3
    anny123 is offline Member
    Join Date
    Nov 2011
    Posts
    9
    Rep Power
    0

    Default Re: can we get the control back to the jsp page after displaying data through servlet

    following mvc pattern - am trying to implement autocomplete using jquery plugin.am getting the location values properly want to retrieve its id also.

    jsp page -

    <script>
    HttpSession session1=request.getSession();
    String buff[][]=session1.getAttribute("locBuffer");
    System.out.println("i am in jsp again");
    System.out.println(buff[0][0]);
    System.out.println(buff[0][1]);
    </script>
    </head>
    <body>
    <div style="width: 300px; margin: 50px auto;">
    <b>Location </b> : <input type="text" id="location" name="location" class="input_text" onselect="getLocationID()"/>
    <br/> <br/><input type="hidden" id="locID" name="locID" class="input_text" />
    // want to display its id in the hidden field

    </div>
    </body>
    <script>
    jQuery(function()
    {
    $("#location").autocomplete("servlet/getList");
    });
    </script>
    <script>
    // searching the selected location and getting its id from the buffer which is retrieved from the servlet
    function getLocationID()
    {
    location=$("#location").val();
    for(int i =0;i<buff.length;i++)
    {
    if(buffer[i][0].equals(location))
    {
    int locid=buffer[i][1];
    }
    }
    System.out.println(locid);
    $("#locID").value=locid;
    }
    </script>


    and in servlet :getList.java


    String query = (String)request.getParameter("q");
    System.out.println(query);
    Master ms=new Master();
    String buffer[][]= ms.retrieveAutoLocation(query); //getting the values loc id and location in string 2d array
    System.out.println("bk in servlet ");

    HttpSession session = request.getSession();
    session.setAttribute("locBuffer", buffer);

    int cnt=1;
    for(int i=0;i<buffer.length;i++)
    {
    //if(buffer[i].toUpperCase().startsWith(query.toUpperCase()))
    //{
    response.getWriter().print(buffer[i][1]+"\n");
    if(cnt>=10)
    break;
    // cnt++;
    //}
    }

    RequestDispatcher rs=getServletContext().getRequestDispatcher("/index.jsp");
    rs.forward(request, response);

    am not getting the o/p.

    am i proceeding the rite way? is there any other alternative fr it? pls guide.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: can we get the control back to the jsp page after displaying data through servlet

    That first <script> block looks like you're trying to write Java in a Javascript area...

    What is it you are trying to do?
    It seems to be an auto-complete Ajax type call?

    In which case "get(ing) the control back to the jsp page" makes no sense...you pass the data from the servlet to the client, which is Javascript by that point.

Similar Threads

  1. Go back to previous page using session in JSP page
    By gopikarikati009 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-23-2011, 10:30 AM
  2. Displaying results from the servlet to jsp web page
    By rushhour in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-17-2010, 12:13 PM
  3. Java in control pannel is not displaying
    By pinki in forum Suggestions & Feedback
    Replies: 10
    Last Post: 08-26-2010, 07:42 AM
  4. posting results back to parent page
    By carag in forum New To Java
    Replies: 0
    Last Post: 07-29-2009, 12:29 PM
  5. how to use back bean JSF page?
    By deru4jesus in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 03-27-2009, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •