• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to make bean object in servlets to get values in jsp

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic