• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to send value of checkbox from one jsp to another using Javabean class?

 
Greenhorn
Posts: 17
Tomcat Server Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm learning advance java these days and I was wondering how to pass values from a personal information form(index.jsp) having checkboxes listing various hobbies to another Jsp page(display.jsp) which displays the values selected by user. I have created the code and it works fine. The only problem is the result is displayed inside square brackets.

Here's my code:
index.jsp


display.jsp



Bean.java //My bean class inside /WEB-INF/classes/pack/Bean.java




So For Example if if user selects Reading and Music,

The result is displayed as [Reading,Music] instead of Music Reading.

Please help to display it normally i.e without the square brackets.
I tried using arrays as return type instead of arraylist as in this case, but that didn't help. Is there any other way to this??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before attending to the square brackets, that's secondary to the most important question: why are you writing your JSPs using technology that's been obsolete for over 12 years?

Putting Java code into a JSP is an obsolete practice that's been discredited since the introduction of JSP 2 in 2002, and replaced since the introduction of the JSTL and EL in 2001. Why would you be learning how to use JSP using such old technology and poor practices?

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. The brackets are because you are using toString() on a list. That's what that method produces. But you need to change the whole approach, as indicated in my first reply, so that's going to go away on its own. What you'll do instead is to return the list, not the string-ification of it, to the JSP, which will iterate over it with the <c:forEach> tag and emit whatever formatted output you want.
 
prerit datta
Greenhorn
Posts: 17
Tomcat Server Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:P.S. The brackets are because you are using toString() on a list. That's what that method produces. But you need to change the whole approach, as indicated in my first reply, so that's going to go away on its own. What you'll do instead is to return the list, not the string-ification of it, to the JSP, which will iterate over it with the <c:forEach> tag and emit whatever formatted output you want.



Seriously?? They dont use Bean classes anymore??? I need to have a talk with my teacher now!!! :censored: You see I'm from India and they don't have many institutes where they teach you Java concepts clearly. I kinda learned basic java on my own. Using Head first java and complete Reference.

I suppose with the problems such as these they sure had a very good reason to do away with it!!

P.S: Maybe my teacher was teaching my old things and so as to learn what prob. occurred with them. Just like you learn C, C++ then java and so on. And yeah I'll be learning JSTL soon in my next class.

Thanks for your help!!!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

prerit datta wrote:Seriously?? They dont use Bean classes anymore???


Please show me where I said beans were not used.

I need to have a talk with my teacher now!!! :censored: You see I'm from India and they don't have many institutes where they teach you Java concepts clearly. I kinda learned basic java on my own. Using Head first java and complete Reference.


Head First is a good book that will also cover modern techniques. You'll probably eventually need to learn about old-fashioned scriptlets in order to deal with legacy code, but you should not be writing new code that uses Java code in a JSP.

I suppose with the problems such as these they sure had a very good reason to do away with it!!


Ding! Ding! We have a winner. There are myriad problems that are solved by not putting Java in a JSP.

P.S: Maybe my teacher was teaching my old things and so as to learn what prob. occurred with them. Just like you learn C, C++ then java and so on. And yeah I'll be learning JSTL soon in my next class.


That's good. Personally I would teach the correct way first -- then teach the antiquated stuff as a "you may come across a TV set that uses vacuum tubes" kinda way.

If you have to use scriptlets because of academic restrictions, that's one thing. Using them in real code is another.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, by the way, I highly recommend these articles:
  • The Secret Life of JSPs
  • The Front Man

  •  
    brevity is the soul of wit - shakepeare. Tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic