How to set the value of a check box dynamically in jsp (values are coming from database) -


sir have jsp file in have display notes there date , description since there can more 1 note(as in scheduler) particular date more 1 notes displayed @ time. want user can modify particular notes in database checking them of check boxes. values of note coming dynamically data base how can set value check box.

fetchcontent.java

public class cnmsdes extends httpservlet{     public void dopost.......{list list=new arraylist();         response.setcontenttype("text/html");         printwriter out = response.getwriter();         system.out.println("oracle connect example.");         connection conn = null;         string url = "jdbc:oracle:thin:@localhost:1521:xe";         string driver = "oracle.jdbc.driver.oracledriver";         string username = "system";          string password = "mint";         statement st;         try {             class.forname(driver).newinstance();             conn = drivermanager.getconnection(url,username,password);             system.out.println("connected database");              string  ndate  = request.getparameter("date");             string  eid  = request.getparameter("empid");             string strar[] = ndate.split("/");             string cdate = strar[0]+"/" + strar[1]+"/"+ strar[2];             if(eid==null||eid=="enter employee id"){response.sendredirect("viewnotes.jsp");}             string query = "select * cnms_notes emp_id='"+eid+"' , note_date='"+cdate+"'";              statement stmt=conn.createstatement();             resultset rs=stmt.executequery(query);               while(rs.next()){                 list.add(rs.getstring("note_date"));                 list.add(rs.getstring("title"));                 list.add(rs.getstring("description"));              }          }         catch(exception e){out.print(e);}         request.setattribute("description",list);         requestdispatcher rd = request.getrequestdispatcher("/displaynotes.jsp");         rd.forward(request, response);     }  } 

and displaynotes.jsp

<%@page language="java" import="java.util.*" %> <html> <body background="images/bg1.jpg">   <table class="t" border="1" width="650" align="center" > <tr><td><form> <tr>             <td width="10"><b></b></td>         <td width="100"><b>date</b></td>         <td width="150"><b>title</b></td>         <td width="100"><b>description</b></td>  </tr>         <% iterator itr;%>         <% list data=(list)request.getattribute("description");              int k=data.size();              request.setattribute("size",k);                 for(itr=data.iterator();itr.hasnext(); ){         %>  <tr class="a">          <td><input type="checkbox" name="cbdate" value="<%=request.getparameter("checkeddate") %>"></td>         <td width="100" ><input type="text" name="checkeddate" value="<%=itr.next()%>" class="b"></td>         <td width="150"><input type="text" name="checkedtitle" value="<%=itr.next()%>" class="b"></td>         <td width="200"><textarea cols="39" rows="3"><%=itr.next()%></textarea></td>  </tr>      <%}      %>   <table><table border="1" align="center"><tr> <td><input type="submit" value="modify" onclick="this.form.action='expriment.jsp';"></td> <td><input type="submit" value="delete" onclick="this.form.action='abc.jsp';"></form></td></tr> </table>  </body> </html> 

what make new list array , add current list object array.

or go ahead , make new class file called notes hold 3 variables have ndate,eid,cdate make getters/setters them. in while (rs.next) loop call new instance of notes class setting each value setter method made, , adding list array made.

public class notes{  date ndate; string title; date cdate; int eid;  //create getter methods //create setter methods } 

now cnmsdes class

public class cnmsdes extends httpservlet{     public void dopost.......{list list=new arraylist();         response.setcontenttype("text/html");         printwriter out = response.getwriter();         system.out.println("oracle connect example.");         connection conn = null;         string url = "jdbc:oracle:thin:@localhost:1521:xe";         string driver = "oracle.jdbc.driver.oracledriver";         string username = "system";          string password = "mint";         statement st;         try {             class.forname(driver).newinstance();             conn = drivermanager.getconnection(url,username,password);             system.out.println("connected database");              string  ndate  = request.getparameter("date");             string  eid  = request.getparameter("empid");             string strar[] = ndate.split("/");             string cdate = strar[0]+"/" + strar[1]+"/"+ strar[2];             if(eid==null||eid=="enter employee id"){response.sendredirect("viewnotes.jsp");}             string query = "select * cnms_notes emp_id='"+eid+"' , note_date='"+cdate+"'";              statement stmt=conn.createstatement();             resultset rs=stmt.executequery(query);              list<notes> noteslist = new arraylist<notes>();             while(rs.next()){                 notes mynotes = new notes;                 mynotes.setndate(rs.getdate("note_date"));                 mynotes.settitle(rs.getstring("title"));                 //you idea                 noteslist.add(mynotes);             }          }         catch(exception e){out.print(e);}         request.setattribute("description",list);         requestdispatcher rd = request.getrequestdispatcher("/displaynotes.jsp");         rd.forward(request, response);     }  } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -