Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet check box  RSS feed

 
John ortega
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forgive me , but im not sure if this is the right forum for servlet help. im getting to that desperate state with my project , my teacher is no help at all and im hoping to get some help here.

im trying to finish this servlet that adds a new course to my courses display. im using a check box so the user can pick what the prerequisite are for the new course they want to add. so if they check cs201 , it will add cs201 as a prerequisite for that new course.

for some reason my checkbox will only add the first checkbox that is clicked. like if i add a subject , and click the check boxs for cs203 , cs202, and cs201. it will only grab cs201 and add it to my course display. it wont grab all 3. how can i grab the other info thats checked?



so then i figured out that i had to use an array to get out all the values. so i did



now with that comes more problems lol. Im assuming i have no choice but to redo my Constructor from


to this right?



so now with that updated , i dont know what do next. is that all i have to do for it to be able to get all the checkbox values? if thats right then all thats left to do is to update my entries. like i did below. but whan those print out to the display. i get some weird characters



i get [Ljava.lang.String;@6fbb45 , in my prerequiite table dipsplay. i tried using toString , but it i get errors that i dont know how to fix.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

John nava wrote:forgive me , but im not sure if this is the right forum for servlet help.


Yup. This is the place!

First of all, check your HTML syntax (Hint: you have quoting problems). *

Secondly, you have a number of checkboxes named prerequisites, so your use of request.getParameter("prerequisites") is not correct. It will, indeed, only give you the first of the checked checkboxes. What you want to use is request.getParameterValues("prerequisites") which will return an array of all the values rather than just the first.






* This is one of the many reasons that building up HTML in strings in servlets isn't a practice that's used much. I'm sure at some point you'll be learning about JSPs which are the preferred way to generate dynamic HTML.
 
John ortega
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Welcome to the Ranch!

John nava wrote:forgive me , but im not sure if this is the right forum for servlet help.


Yup. This is the place!

First of all, check your HTML syntax (Hint: you have quoting problems). *

Secondly, you have a number of checkboxes named prerequisites, so your use of request.getParameter("prerequisites") is not correct. It will, indeed, only give you the first of the checked checkboxes. What you want to use is request.getParameterValues("prerequisites") which will return an array of all the values rather than just the first.






* This is one of the many reasons that building up HTML in strings in servlets isn't a practice that's used much. I'm sure at some point you'll be learning about JSPs which are the preferred way to generate dynamic HTML.



oops yeah i fixed that html syntax around my prerequisites syntax. and i did use what you were talking about.
if you look down under my servelet code on my post , i did that and im stuck on what to do next lol
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get [Ljava.lang.String;@6fbb45 , in my prerequiite table dipsplay. i tried using toString , but it i get errors that i dont know how to fix.


Where do you get that? You haven't posted the code/page which makes uses of the "entries" attribute.
 
John ortega
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops sorry about that. this is my Coure Display servlet that diplays all the courses. my addcourse servlet is supposed to add classes to that. and just incase ill post the class that holds all my data. those are the 3 things ive been using in my project so far. the display( which diplays my courses) , the addCourse( which add a new course to the display) , and the Course class(which holds all my data).





 
John ortega
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and i really appreciate the help. My teacher is useless and i cant find a tutor to help me. so im pretty much on my own and its scary lol.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in essence, you are printing out the prerequisites of a course as follows:

out.println("<tr><td>" + entry.getCode() + "</td><td>"
+ entry.getTitle() + "</td><td>" + entry.getprerequisites()
+ "</td><td> Edit</td></tr>");


which ultimately is a column within a row for that course.

Going back to what you did in your first post where you pass along a
String[] to the constructor of the Courses class (I would actually just name it Course instead of Courses, but that's a different matter), that's the right thing to do since your course can have multiple prerequisites. So it now becomes a matter of displaying those multiple prerequisites in that single column of the row.

entry.getprerequisites() would now return an array and a .toString() on it (which is what you are doing when you use the + operator for string concatenation) would return the "weird" output that you are seeing. What you really need to do is, iterate over that array to get to the individual values in it and display that either in a single column or multiple columns. Something like:


(or some such thing).

The important point in that is that you have to get to the individual items in that array.
 
John ortega
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alright , i see what you mean, but would i do this in the display or the in the adding part? im alittle confused on how it all fits together.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!