This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing boolean from jsp checkbox into arraylist using bean

 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bean from the instructor and the task is to use the bean to store data that is being retrieved from a jsp then added to an arraylist that is then forwarded to another jsp. There are two values coming from checkboxes on the first jsp form so they are boolean. I don't understand how to store them in the arraylist but it must be possible because the instructor has them as boolean in the bean. I doubt I am loading the arraylist correctly because I have seen other threads where strings and integers can be stored in the same arraylist. The thrid compile error also has to do with the arraylist, I thought .add was inherited .

Instructor's bean.



The servlet code


The errors on the ant compile

 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message is rather explicit. You want to put a String where a boolean is expected.

BookServlet.java:54: setPaperback(boolean) in com.javaranch.drive.books.BookData cannot be applied to (java.lang.String)
[javac] newbook.setPaperback(servletData.getParameter("paperback"));

 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand the error message. I do not understand where the String is coming from.

Am I misunderstanding what a checkbox parameter value is that is coming back from a servlet -- and it is a String not a boolean?
 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
servletData - which type is it of?

What does its getParameter method return? (Well, obviously String.)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All request parameters are strings. Always. That's the way HTTP works.

If a value is something that needs to be converted to something else (a boolean for example) you'll need to write code to do that.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All request parameters are strings. Always. That's the way HTTP works.


Thank you, Bear.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic