Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4547586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:06:45+00:00 2026-05-21T16:06:45+00:00

I am currently learning jsp/servlet, and trying to make an online bookstore. Using jquery,

  • 0

I am currently learning jsp/servlet, and trying to make an online bookstore. Using jquery, I was able to send the GET request to the servlet. Upon success, it will reload the browseBookArea div with browseBookArea.jsp. What I don’t understand is, this procedure causes infinite loop on my glashfish servet (it happens within the BrowseBookTag.java. I put a System.out.println there to check it).

Is there another way to get the data returned from servlet to Jquery, so I can do it properly? Setting variables in session is not a good way for this I think. I saw the example with jquery.get where we can get the response data.

  var currentCat = "all";
  $(document).ready(function(){
    $(".categoryItem").click(function(event){
         $("#browseBookArea").fadeToggle(100);
         currentCat = $(this).attr("id");
         $.get("GetBookFromCategoryServlet",{selectedCat:currentCat, currentPage:1});                               });    
   $("#browseBookArea").ajaxSuccess(function(){                               
         $(this).show(300);
         $(this).load("Components/browseBookArea.jsp");
    });

   $(".pagination").click(function(event){
         $("#browseBookArea").fadeToggle(100);
         var page = $(this).attr("id");
         alert(currentCat);
         $.get("GetBookFromCategoryServlet",{selectedCat:currentCat, currentPage:page});
      });
});

Here is my browseBookArea.jsp:

<div id="browseBookArea" class="span-15 last">
    <%System.out.println("Back from servlet");
      Collection c = (Collection) request.getAttribute("booksFromCat");
      if (c == null) {
          Collection c1 = (Collection) session.getAttribute("booksFromCat");
          if (c1 == null) System.out.println("Books are null");
      }
    %>
    <myJavaTags:BrowseBookTag books="${booksFromCat}" pageSize="${pageSize}" >
        <c:if test="${not empty book1 }">
            <div class="span-7">
                    <center>
                        <img width="115px" height="115px" src='${book1.photoPath}.jpg'/>
                        <p>${book1.price}<br/><a>${book1.title}</a> <br/>${book1.authorName}<p>
                    </center>
            </div>
        </c:if>
        <c:if test="${not empty book2 }">
            <div class="push-1 span-7 last">
                <center>
                        <img width="115px" height="115px" src='${book2.photoPath}.jpg'/>
                        <p>${book2.price}<br/><a>${book2.title}</a> <br/>${book2.authorName}<p>
                </center>
            </div>
        </c:if>
    <hr class="space">
    </myJavaTags:BrowseBookTag>
    <hr class="space"/>
</div>

My BrowseBookTag:

 public void doTag() throws JspException, IOException{
//        if (books ==null){
//            admin = AdminBeanFactory.getAdminInstance();
//            books = admin.browseBook(cat);
//        }
        Iterator bookIt = books.iterator();
        JspContext jsp = getJspContext();
        int i = 0, count = 0;
        System.out.println("Total book size in browse tag: "+books.size());
        while (bookIt.hasNext() && i < pageSize){
            BookDTO b = (BookDTO) bookIt.next();
            if (count == 0){
                jsp.setAttribute("book1", b);
                if ((i+1) == pageSize){
                    jsp.setAttribute("book2", null);
                    getJspBody().invoke(null);
                }
                count++;
            }else{
                jsp.setAttribute("book2", b);
                getJspBody().invoke(null);
                count = 0;
            }
            i++;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:06:46+00:00Added an answer on May 21, 2026 at 4:06 pm

    I found the culprit. It is:

    $("#browseBookArea").ajaxSuccess(function(){                               
             $(this).show(300);
             $(this).load("Components/browseBookArea.jsp");
        });
    

    Bad, bad, bad. This demonstrates that I didn’t know the meaning of success method call. I’ve just realized that if I let the #browseBookArea div to load every time, it causes a successful operation, and then it will perform again which ultimately leads to recursion. Finally I got out of this pitfall. The correct thing should be:

    $(".categoryItem").click(function(event){
          $("#browseBookArea").fadeToggle(100);
          var currentId = $(this).attr("id");
          $.get("GetBookFromCategoryServlet",{selectedCat:currentId, currentPage:1}, function(data){
                 $("#browseBookArea").fadeIn(300); 
                 $("#browseBookArea").load("Components/browseBookArea.jsp");                                  
                 });
          }); 
    

    I just need to define a successful handler after the GET request, and the successful handler must not be the div which invokes the operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im currently learning jQuery and have ran into a problem. I am trying to
So I am currently learning C++ and decided to make a program that tests
I'm learning XML, currently of Wikibooks, but that is kinda huge and not oversee-able...
I'm currently learning Java EE, or more specifically, Servlets and .jsp. In my programming,
I am currently learning jQuery, and I am curious about something. For functions that
I'm currently learning the BSON java library for mongodb and I'm trying to transform
I'm currently learning about concurrency in C++ and came across using a vector of
I am currently learning MVVM abd the tutorial I have been using, simply uses
I currently learning about scrum and want to learn from experienced professionals in the
I'm currently learning Haskell, Which language (F# or Haskell) do you prefer for programming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.