Fail to populate html table with java hashmap using servlet and jsp -


i have employeedb class set connection db , can retieve data db. in class have func called getallemaployee use retrieve data, looks this:

public class employeedb {      private connection connection;      public employeedb() {         connection = dbutil.getconnection();     }      public hashmap<string, list<string>> getallemployee() throws filenotfoundexception, unsupportedencodingexception {          hashmap<string, list<string>> total = new hashmap<>();          try {              statement statemente = connection.createstatement();             preparedstatement pstatement = connection.preparestatement("select month paycheck id=?");              resultset rse = statemente.executequery("select id employee");               while (rse.next()) {                     list<string> months = new arraylist<>();                  pstatement.setstring(1, rse.getstring("id"));                 resultset rs = pstatement.executequery();                   while (rs.next()) {                     months.add(rs.getstring("month"));                 }                  total.put(rse.getstring("id"), months);             }          } catch (sqlexception e) {              e.printstacktrace();          }         return total;     } } 

now, im calling method servlet "employeeinfo" , returning hashmap have pairs of data need (i printed , saw have correct data).

now want servlet set hashmap attribute of session, go jsp file , populate table hashmap data. servlet:

public class employeeinfo extends httpservlet {      private final employeedb edb;      public employeeinfo() {         super();         edb = new employeedb();     }      @override     protected void dopost(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {         string forward = "";         employee e = new employee();         employee retemp = new employee();         hashmap<string, list<string>> total = new hashmap<>();         e.setid(request.getparameter("id"));          try {             retemp = edb.getempinfo(e.getid());              if (e.getid().equals("")) {                 total=edb.getallemployee();                 request.getsession().setattribute("employeehashmap", total);                 forward = "allemployee.jsp?";             }                         else if (retemp.getid() == null) {                 forward = "errorid.jsp?";             } else {                  request.getsession().setattribute("newemployee", retemp);                 forward = "welcomeuser.jsp";             }             requestdispatcher view = request.getrequestdispatcher(forward);             view.forward(request, response);          } catch (sqlexception ex) {             logger.getlogger(employeeinfo.class.getname()).log(level.severe, null, ex);         }      }  } 

now in allemployee.jsp want populate table , looks this:

<!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>jsp page</title>     </head>     <body>         <table id="ptable" border="1">              <tr>                 <td style="text-align: center;">id</td>                 <td style="text-align: center;">month</td>             </tr>             <c:foreach var="entry" items="${employeehashmap}" >                 <!-- entry.key employee.key -->                 <!-- entry.value employee.skills -->                 <c:foreach var="skillid" items="${entry.value}" >                     <tr>                         <td>${entry.key}</td>                         <td>${skillid}</td>                     </tr>                 </c:foreach>             </c:foreach>         </table>     </body> </html>type message 

i have no idea why not working , can see empty table... please try me figure out. thanks!!!


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -