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 7800397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:37:23+00:00 2026-06-02T00:37:23+00:00

I have the next jsp file called Bookstore.jsp , in which I filled up

  • 0

I have the next jsp file called Bookstore.jsp, in which I filled up a table with data from a database.

<%
ArrayList<Book> b = new ArrayList<Book>();
b = SqlSentencesList.showCatalog(); // this method returns an arrayList with all books
%>

<form method="get" action="ShoppingCarController">
    <table border="2">
        <tr>
            <th>ISBN</th>
            <th>Title</th>
            <th>Author</th>
            <th>Price</th>
            <th>Select</th>
        </tr>

        <%for(int i=0; i<l.size();i++){%>
            <tr>
                <td> <%out.print(b.get(i).getIsbn());%> </td>
                <td> <%out.print(b.get(i).getTitle());%> </td>
                <td> <%out.print(b.get(i).getAuthor());%> </td>
                <td> <%out.print(b.get(i).getPrice());%> </td>
                <th> <input type="checkbox" name="checkboxGroup" value="<%Integer.toString(i);%>"/> </th>
            </tr>
        <% } %>
    </table>
    <input type="submit" value="Add to shopping car"/>
</form>

Now, I need the same book data (ISBN, title, author and price) in the Servlet, but just from the ones selected.

This’s my doGet method from ShoppingCarController servlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ArrayList<Book> shoppingCar = new ArrayList<Book>();

        String[] values = request.getParameterValues("checkboxGroup");

        for(int i=0; i<values.length; i++) {
            System.out.println(values[i]);
        }
    }

I tried to printed it to see what I’m getting, but nothing shows up in the console.

I was looking at this similar case: How to pass data from selected rows using checkboxes from JSP to the server and I think my problem is with the value attributes, but I don’t know the syntax used in that question, don’t understand that for each and the <c:out tags; in short, I don’t know how to adapt my code to get it work.

Someone give me a hand with that.

  • 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-06-02T00:37:24+00:00Added an answer on June 2, 2026 at 12:37 am

    your jsp should look somethin like this (using the servlet code you have posted)

    first edit your servlet and include:

    ArrayList<Book> shoppingCar = new ArrayList<Book>();
    request.setAttribute("b", shoppingCar);//accsessed as ${b} in jsp
    

    in your jsp you will have:-

         <form action="yourserlet" method="POST">
                    <table>
                        <thead>
                            <tr>
                                <td width="10%">ISBN</td>
                                <td width="30%">TITLE</td>
                                <td width="30%">AUTHOR</td>
                                <td width="20%">SELECT</td>
                            </tr>
                        </thead>
    
                        <tbody>
    
            <c:forEach items="${b}" var="book">  
                     <tr>     
                       <td align="left"><input type="text" name="isbn<c:out value="${book.isbn}"/>"  disabled="true"/></td>                     
                         <td align="left"><input type="text" name="title<c:out value="${book.title}"/>"  disabled="true"/></td> 
                         <td align="left"><input type="text" name="author<c:out value="${book.author}"/>"  disabled="true"/></td> 
                         <td align="left"><input type="text" name="price<c:out value="${book.price}"/>"  disabled="true"/></td>
                         <td align="center">  
                            <input type="checkbox" name="checkboxgroup"   
                                value="c:out value="${book.tostring()}"/>"/>  
                         </td>  
                      </tr>  
                 </c:forEach>   
          </tbody>
                    </table>
                </form>
    

    the you should possibly use jquery to enable or disable a field on checking a checkbox, i have disabled them by default.

    check also:

    jQuery – checkbox enable/disable

    Getting all selected checkboxes values using ajax and jsp/servlets?

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

Sidebar

Related Questions

I have jsp page which diplays a huge data in table format in the
I have a JSP file that runs a select statement against an Oracle database.
I have to retrieve the more than 100 records from the Database table using
I have a JSP file Signup.jsp which submits to UserDetails servlet which inserts the
I have a JSP page and it should get all the images from database
I have a JSP file which I am deploying within a Java Project with
I have next problem, when I'm trying to retrieve value from xforms:select elements I
i have question about YAJLiOS parser... I have next json data : {{ body
in my jsp i have a table constructed dynamically like the following: ' retour.append();
I am a programmer, new to jsp, trying to write some code. i have

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.