I am new to Struts and want to display the Registration ID which is generating automatically by the mysql to my success page when user submits the form, please guide me how to achieve it...
My Action... package net.Candidate.application.action; import java.io.*; import java.sql.*; import java.util.*; import javax.naming.*; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ActionContext; import net.database.*; import net.Candidate.application.model.Apply; import net.Candidate.application.model.Appform; public class SubmitAppFormAction extends ActionSupport { private Appform appform; private int onlineID = 0; public String add() { try { Connection connect = null; ResultSet result = null; PreparedStatement pstmt = null; DBConnection getConnect = new DBConnection(); connect = getConnect.getCon(); System.out.println("JDBC MySQL Connection...."); String query = "INSERT INTO applicant VALUES(NULL,?,?,?,?,?,?.........NOW())"; pstmt = connect.prepareStatement(query); pstmt.setString(1, appform.getName()); pstmt.setString(2, appform.getSurname()); pstmt.setString(3, appform.getDOB()); pstmt.setString(4, appform.getGender()); pstmt.setString(5, appform.getNationality()); pstmt.setString(6, appform.getEmail()); ........................ ........................ pstmt.executeUpdate(); *int OnlineID = 0;* ResultSet result_ID = null; String IDqry = "Select OnlineID from applicant where Email=?"; pstmt = connect.prepareStatement(IDqry); pstmt.setString(1, appform.getEmail()); result_ID = pstmt.executeQuery(); { while (result_ID.next()) { OnlineID = result_ID.getInt(1); } } String Securityquery = "INSERT INTO security VALUES("+OnlineID+",?,?,?,?)"; pstmt = connect.prepareStatement(Securityquery); pstmt.setString(1, appform.getEmail()); pstmt.setString(2, appform.getReferee1Email()); pstmt.setString(3, appform.getReferee2Email()); pstmt.setString(4, appform.getPasswd()); pstmt.executeUpdate(); * setOnlineID(this.onlineID); return "success";* } catch (SQLException e) { e.printStackTrace(); } return SUCCESS; } *public int getOnlineID() { return onlineID; } public void setOnlineID(int onlineID) { //Implementation of the application specific logic to retrieve the data from the database// try { Connection connect = null; PreparedStatement pstmt = null; DBConnection getConnect = new DBConnection(); connect = getConnect.getCon(); int OnlineID = 0; ResultSet result_OID = null; String OIDqry = "Select OnlineID from applicant where Email=?"; pstmt = connect.prepareStatement(OIDqry); pstmt.setString(1, appform.getEmail()); result_OID = pstmt.executeQuery(); { while (result_OID.next()) { OnlineID = result_OID.getInt(1); } } } catch (SQLException e) { e.printStackTrace(); } }* public Appform getAppform() { return appform; } public void setAppform(Appform appform) { this.appform = appform; } } I TRIED BY THE METHOD HIGHLIGHTED IN BOLD: I want to display the OnlineID which is generated on my JSP page, but it is showing OnlineID as 0. My JSP: <%@ taglib prefix="s" uri="/struts-tags" %> <div id="heading"> <s:text name="title_applysuccess"/> </div> <div id="index"> <s:text name="apply_Success"/> <s:text name="apply_SuccessID"/><s:property value="%{onlineID}"></s:property> </div> Please help........ -- View this message in context: http://struts.1045723.n5.nabble.com/How-to-display-data-from-database-to-JSP-Page-in-Struts2-tp4566721p4566721.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org