• 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 make bean object in servlets to get values in jsp

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here i have to make bean object in servlet , where i have to make connection and execute query and then i have to use that result set in jsp using bean as there is multiple values i have to insert within single variable that has to be print on jsp within single dropdown.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use a List to store the data. Store that List as an attribute, then use <c:foreach> to loop through that List.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:You can use a List to store the data. Store that List as an attribute, then use <c:foreach> to loop through that List.


can you please tell me syntax or give me any short example to use bean as i never used bean before.
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assume you have a class to represent your data:
Inside your servlet, you create a List (ArrayList, LinkedList, ...). You fill it with instances of Person. You set that as an attribute; keep the scope as short as possible, so preferably request scope. For example:
You now forward the request to your JSP. There all you need it a forEach tag:
The forEach tag will take the List for attribute results, loop over it, and assign each element to loop variable person. The EL inside the loop will call person.getName() and person.getAge() for each element. As you can see, inside the EL you remove the get and turn the first letter after that into lowercase.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Assume you have a class to represent your data:
Inside your servlet, you create a List (ArrayList, LinkedList, ...). You fill it with instances of Person. You set that as an attribute; keep the scope as short as possible, so preferably request scope. For example:
You now forward the request to your JSP. There all you need it a forEach tag:
The forEach tag will take the List for attribute results, loop over it, and assign each element to loop variable person. The EL inside the loop will call person.getName() and person.getAge() for each element. As you can see, inside the EL you remove the get and turn the first letter after that into lowercase.



in my college server jstl or etl is not enabled so can you please tell me jsp only how can i insert values from servlet to jsp dropdown
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic