wie jsp-Anfrage senden Parameter servlet

ich bin neu in jsp und baute meine erste Anwendung. Ich bin nach einem Buch. Das Buch verwendet eine 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>

und in den servlet-code ist

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()

Meine Frage ist wenn ich auf hinzufügen in den Warenkorb button Hinzufügen, dann in den servelt an der Linie String myBook = request.getParameter("book"); ich bekomme das Buch als ein parameter, aber in meiner jsp habe ich nicht sagen, dass request.setAttribute("book", "book"), das gleiche gilt für request.getParameter("qty");. Wie mein servlet empfängt diesen request-Parameter, ohne es im jsp-code?
Dank

InformationsquelleAutor Basit | 2012-06-15
Schreibe einen Kommentar