Reputation: 1225
I Have a servlet where i have returned a list :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("inside doPost of Role Management ---");
this.context = request.getServletContext();
UserProperties userProp;
try{
userProp= new UserProperties();
//just a place holder to see if the property file can be read...
userGroup_DS_Proxy = userProp.ReadProperties("UserGroup_DS_Proxy").toString();
System.out.println("Properties file location was found in th tomcat folder");
}catch(Exception ex){
userProp= new UserProperties(context);
System.out.println("Fail Safe Mode Activated");
}
userGroup_DS_Proxy = userProp.ReadProperties("UserGroup_DS_Proxy").toString();
roleManagementDebug = Boolean.valueOf(userProp.ReadProperties("RoleManagementDebug").toString());
RoleManagementDAO roleManagementDAO= new RoleManagementDAO(roleManagementDebug,userGroup_DS_Proxy);
if(roleManagementDebug){
System.out.println("new post for Role Management");
}
List<String> roles = roleManagementDAO.getRoles();
HttpSession session = request.getSession(true);
session.setAttribute("RoleList", roles);
}
Now i am passing the list by setting it in HttpSession as : session.setAttribute("RoleList", roles);
Now i want to get this session value in the jsp and populate a dropdown with this session variable. Since i don't have much knowledge of JSP side, It is getting really hard for me to solve this problem. How can i do this? Looking forward to your answers. Thanks in advance
Upvotes: 0
Views: 1662
Reputation: 2949
you can use jstl tag and display the list instead of trying with scriptlet (<% %>). In your header of jsp,
<%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
You can check here for info.
<c:forEach var="listVar" items="${listName}"> //In your case RoleList
<option value ="${listVar.attribute1}">
<c:out value="${listVar.attribute2}"/>
</option>
</c:forEach>
Hope this helps.
Upvotes: 1