Hello Sir,
I am facing the problem while fetching the database value on jsp page while using struts2.0 and hibernate3.0 and MySql try to help me resolve this problem and try to tell me what should i do for fetch the database value and shown on jsp page.
AdminProvideLeave Pojo Class package mypack; > public class AdminProvideLeave { > > private static long serialVersionUID = > 1L; > > private int rpl, rcl, rsl, rel, > serial_no, rtotal_leave; > > public AdminProvideLeave() { super(); > // TODO Auto-generated constructor > stub } > > public AdminProvideLeave(int rpl, int > rcl, int rsl, int rel, int > rtotal_leave, int serial_no) { > super(); this.rpl = rpl; this.rcl = > rcl; this.rsl = rsl; this.rel = rel; > this.serial_no= serial_no; > this.rtotal_leave= rtotal_leave; } > > public static long > getSerialVersionUID() { return > serialVersionUID; } > > public static void > setSerialVersionUID(long > serialVersionUID) { > AdminProvideLeave.serialVersionUID = > serialVersionUID; } > > public int getRpl() { return rpl; } > > public void setRpl(int rpl) { this.rpl > = rpl; } > > public int getRcl() { return rcl; } > > public void setRcl(int rcl) { this.rcl > = rcl; } > > public int getRsl() { return rsl; } > > public void setRsl(int rsl) { this.rsl > = rsl; } > > public int getRel() { return rel; } > > public void setRel(int rel) { this.rel > = rel; } public int getSerial_no() { return serial_no; } > > public void setSerial_no(int serialNo) > { serial_no = serialNo; } > > public int getRtotal_leave() { return > rtotal_leave; } > > public void setRtotal_leave(int > rtotalLeave) { rtotal_leave = > rtotalLeave; } > > > } > // AdminProvidLeaveAction Class package > mypack; > > import java.util.*; import > java.util.List; > > import > com.opensymphony.xwork2.ActionSupport; > > public class AdminProvideLeaveAction > extends ActionSupport { private static > final long serialVersionUID= 1L; > public AdminProvideLeave apl; public > List<AdminProvideLeave>apllist; Dao > dao= new Dao(); public String > execute() { > > dao.save(apl); return "success"; } > > public String fetch() { > > apllist=dao.fetch1(); return > "success"; } > > public AdminProvideLeave getApl() { > return apl; } > > public void setApl(AdminProvideLeave > apl) { this.apl = apl; } public > List<AdminProvideLeave> getApllist() { > return apllist; } > > public void > setApllist(List<AdminProvideLeave> > apllist) { this.apllist = apllist; } > > public static long > getSerialversionuid() { return > serialVersionUID; } > > } // Dao Class import java.util.ArrayList; > import java.util.List; import > org.hibernate.HibernateException; > import org.hibernate.Query; import > org.hibernate.Session; import > org.hibernate.SessionFactory; import > org.hibernate.Transaction; import > org.hibernate.cfg.Configuration; > > public class Dao { > > public void save(Object O) { > Configuration cfg = new > Configuration().configure(); > SessionFactory f = > cfg.buildSessionFactory(); Session > session = f.openSession(); Transaction > t = session.beginTransaction(); > session.save(O); t.commit(); > session.close(); } > > @SuppressWarnings("unchecked") public > List<AdminProvideLeave>fetch1()// for > fetch the value from database on jsp > page { > > Configuration cfg = new > Configuration().configure(); > SessionFactory f = > cfg.buildSessionFactory(); Session > session = f.openSession(); Transaction > t = session.beginTransaction(); > List<AdminProvideLeave>apllist = new > ArrayList<AdminProvideLeave>(); try { > Query q = session.createQuery("from > AdminProvideLeave"); apllist = > q.list(); } catch (HibernateException > he) { System.out.println(he); } > t.commit(); session.close(); return > apllist; } > > @SuppressWarnings("unchecked")// For > insert the value in database public > List<AdminProvideLeave> apllist() { > Configuration cfg = new > Configuration().configure(); > SessionFactory f = > cfg.buildSessionFactory(); Session > session = f.openSession(); > Transaction t = > session.beginTransaction(); > List<AdminLeavePojo> adlp = null; > try { Query q = > session.createQuery("from > AdminProvideLeave"); adlp = > q.list(); > } catch (HibernateException e) { System.out.println(e); } > t.commit(); session.close(); > > return adlp; } } // ---------------- > > Struts.xml <action > name="adminaddleave" > class="mypack.AdminProvideLeaveAction" > method="execute"> <result > name="success">welcome2.jsp</result> > <result name="success" type="redirect">fetch</result> </action> <action name="fetch" class="mypack.AdminProvideLeaveAction" method="fetch"> <result name="success">viewleave.jsp</result> // ViewLeave.jsp align="center"> <s:form theme="simple" method="post" name="rempleave"> <s:label>Employee Remaining Leave:</s:label> <table border="" align="center" style="margin-top: 28px"> <s:iterator value ="apllist" var="empleave"> <tr> <td> <s:property value="rcl"/> </td> </tr> </s:iterator> <!-- <tr style="height: 40px"> <td style="width: 200px; text-align: center"> <b>Leave Type</b> </td> <td style="width: 100px; text-align: center"> <b>Leave</b> </td> </tr> --> <tr style="height: 40px"> <td style="width: 200px; text-align: center"> RPL </td> <td id="pl" style="text-align: center" name="rpl"> </td> </tr> <tr style="height: 40px"> <td style="width: 200px; text-align: center"> RCL </td> <td id="cl" style="text-align: center" name="rcl"> </td> </tr> <tr style="height: 40px"> <td style="width: 200px; text-align: center"> RSL </td> <td id="sl" style="text-align: center" name="rsl"> </td> </tr> <tr style="height: 40px"> <td style="width: 200px; text-align: center"> REL </td> <td id="el" style="text-align: center" name="rel"> </td> </tr> <tr style="height: 40px"> <td style="width: 200px; text-align: center"> RLWP </td> <td id="lwp" style="text-align: center" name= "rlwp"> </td> </tr> <tr style="height: 40px"> <td style="width: 200px; text-align: center"> <input type="button" value="R Leave" onclick=Total(); </td> <td id="total" style="text-align: center"> </td> </table> </s:form>`print("code sample");
Ads