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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 182

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: 19541
    
  16

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: 182

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: 19541
    
  16

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: 182

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to make bean object in servlets to get values in jsp
 
Similar Threads
resetting form view values
Action form - design issue
forwarding request to an action from a jsp page
IBM Exam 157 - Questions and Answers (Sample Exam)
Creating a class within JSP to be shared among pages