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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:59:26+00:00 2026-06-06T14:59:26+00:00

i am new to jsp and just built my first application. I am following

  • 0

i am new to jsp and just built my first application. I am following a book. The book used a code

<form name="addForm" action="ShoppingServlet" method="post">
    <input type="hidden" name="do_this" value="add">

    Book:
    <select name="book">                   

    <%  
        //Scriplet2: copy the booklist to the selection control
        for (int i=0; i<bookList.size(); i++) {

            out.println("<option>" + bookList.get(i) + "</option>");

         } //end of for
     %>                   
     </select>

     Quantity:<input type="text" name="qty" size="3" value="1">               
     <input type="submit" value="Add to Cart">

</form>

and in the servlet the code is

else if(do_This.equals("add")) {

    boolean found = false;
    Book aBook = getBook(request);
    if (shopList == null) { // the shopping cart is empty

        shopList = new ArrayList<Book>();
        shopList.add(aBook);

    } else {...  }// update the #copies if the book is already there

private Book getBook(HttpServletRequest request) {

    String myBook = request.getParameter("book");   //confusion
    int n = myBook.indexOf('$');
    String title = myBook.substring(0, n);
    String price = myBook.substring(n + 1);
    String quantity = request.getParameter("qty");  //confusion
    return new Book(title, Float.parseFloat(price), Integer.parseInt(quantity));

} //end of getBook()

My question is when i click on add Add to Cart button then in the servelt at line String myBook = request.getParameter("book"); i get book as a parameter but in my jsp i didn’t say that request.setAttribute("book", "book"), same for request.getParameter("qty");. How my servlet is receiving these request parameters without setting it in jsp code?
Thanks

  • 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-06T14:59:27+00:00Added an answer on June 6, 2026 at 2:59 pm

    You get that parameter because in your form you have this:

    <select name="book">
    

    The user never does a request.setParameter (such a method is not even defined)

    You can also set a parameter by invoking the servlet with a query string. Something like:

    http://localhost:8080/ShoppingServlet?name=abcd&age=20
    

    The above will create two request parameters named abc and age which you can access using request.getParameter

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

Sidebar

Related Questions

i am new in JSP,i have some problem with the following code : <%@
I am new to JSP and generating a form with a text area. Is
I am new to JSP and don't have much idea. So just let me
I'm just starting to learn JSP (and I'm pretty new to Java in general),
I have following class that send the value of name variable but the jsp
I'm new bee to spring. Just started my sample application in sprinv mvc. But,
First off thank you for reading! So I just learned JSP's and Servlets this
I'm new to JSP, using Eclipse, and am trying to just get started with
I'm new to JSP so with this question I'm really just wondering if I
I have a web application built using jsp/servlets.The web application session is set to

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.