0

how to do this in jsp? Where User will be java Servlet handling user profile by id? This is way how would I write in php:

Login name  lastname 
user1 name1 lastname1  <a href="User?id=1>profile</a>
user2 name2 lastname2  <a href="User?id=2>profile</a>
user3 name3 lastname3  <a href="User?id=3>profile</a>

I want to do it jsp it will be probably same, but is I just need to get servlet User.java and somehow information about the user depending on the line. The users are also printed from java bean user, so I may post all the java bean user. Is it posible? Is it posible to post parameter to the servlet some other way then by the get parameter by post or some redirect?

user1097772
  • 3,499
  • 15
  • 59
  • 95

1 Answers1

1

To get a list of users from your data source and pass it to your JSP, you can populate a List in your servlet and add it as an attribute on the request object:

List<User> data = yourDao.list();
request.setAttribute("usersList", data);

To display this list of users in you JSP, you then use a simple loop:

<c:forEach var="user" items="${usersList}">
    Name: ${user.name}
    ...
</c:forEach>

See also:

Community
  • 1
  • 1
Med
  • 628
  • 9
  • 29
  • Sorry there was a problem with using tag code, so stackoverflow didn't show part of my question. That thing what you answer is what I already have as imput. I want to show profile of one user from the list and I just wanted to know if is posible to do it different way than using get parameter. My solution is next to each user is link to profile with get parameter, href is on servlet which select select the user by the parameter and forward to userProfile.jsp – user1097772 Jan 11 '13 at 07:57
  • Well, you could preload a `profilesList` along with the `usersList`, and then use some JS to instantly display it onclick in your JSP. This way, you wouldn't need to send another request to the server to get a profile, but the first and only request would be greedier. – Med Jan 11 '13 at 08:04