aspose file tools*
The moose likes JSP and the fly likes how to make bean object in servlets to get values in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to make bean object in servlets to get values in jsp" Watch "how to make bean object in servlets to get values in jsp" New topic
Author

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

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 200

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

Joined: Oct 27, 2005
Posts: 19672
    
  18

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 200

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

Joined: Oct 27, 2005
Posts: 19672
    
  18

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

Joined: Feb 28, 2012
Posts: 200

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to make bean object in servlets to get values in jsp