Hi I need immediate solution for this problem, Hi I have a struts login page which get an Email_ID and Password name login.jsp.When I click the submit It is forwarded to the Action called loginAction where I have the execute method of the Action which execute and a call to the different method in different class is made to increament the count in the database. My problem is when a click is made to the submit button the execute method is executing twise so if the count in the databse is 1 it is incrementing twise. Regards, vasantha
Regards,Vasantha<p>Great minds discuss ideas. Average minds discuss events. Small minds discuss people.
The BigBarber
Greenhorn
Joined: Mar 30, 2004
Posts: 9
posted
0
Something must be wrong in your bean in which you are connecting to the database. Double check it. Either you are not closing the connection after inserting the data into the data base so that the connection remain open. This may create identical rows in the table but will not insert a value twice. Try printing the intermediate steps either to the log or to the console and find out the problem. [ April 22, 2004: Message edited by: The Big Barber SSSS ]
Vasantha Prabha
Ranch Hand
Joined: Oct 02, 2003
Posts: 108
posted
0
I have the proper closed connection. for the first time when I load the page when I started the server it is incrementing fine but When I logout that is redirect to the page where I enter the login ID.Then I submit this is execute is executing twise before it is forward to the next page that is mapping.findForward(...);
Regards, vasantha prabh
The BigBarber
Greenhorn
Joined: Mar 30, 2004
Posts: 9
posted
0
can you post your code then it can be corrected.
Vasantha Prabha
Ranch Hand
Joined: Oct 02, 2003
Posts: 108
posted
0
public class check extends DispatchAction { Hi this is what my Action page has.... What is wrong in it. When an action is fired it is printing two times the "welcome" public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest Request,HttpServletResponse Response) throws Exception { String emailAddress =(String)((BaseActionForm)form).get("emailAddress"); String password = (String)((BaseActionForm)form).get("password"); System.out.println("Welcome"); return mapping.findForward(Constants.SUCCESS); } }
The BigBarber
Greenhorn
Joined: Mar 30, 2004
Posts: 9
posted
0
I have tried the same application by creating a jsp page one action class one form bean and another java bean as in your case to access the database and it is running absolutly fine. I cannot figure out why it cannot work out for you. OK. I m posting my code find out the problem urself. LogonAction.java **************** package ideas; import javax.servlet.http.*; import javax.servlet.*; import org.apache.struts.action.*; import javax.sql.*; import java.sql.*; public class LogonAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) { Logon l = (Logon)form; String Uname = l.getUname(); String Passwd = l.getPasswd(); if(Uname.equals("ADMIN")){ if(Passwd.equals("admin")){ return mapping.findForward("Logon"); } } bean BEAN = new bean(); try{ BEAN.create(Uname); }catch(Exception e){System.out.println(e);} return mapping.findForward("LogonError"); } } Bean.java ********* package ideas; import java.sql.*; import javax.sql.*; import javax.naming.*;
public class bean { public void create(String name) throws Exception{ Context ctx = new InitialContext(System.getProperties()); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/struts"); Connection con = ds.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select max(IND) from struts_index"); rs.next(); int index = Integer.parseInt(rs.getString(1)); System.out.println("index::"+index); stmt.executeUpdate("insert into struts_index values ("+ ++index +",'"+name+"')"); stmt.close(); con.close(); } } Struts-config.xml ***************** A Part of my Struts-Config.xml Contains the following. <!-- ========== Form Bean Definitions =================================== --> <form-beans> <form-bean name="Logon" type="ideas.Logon"/> </form-beans> <!-- ========== Global Forward Definitions ============================== --> <global-forwards> <forward name="Blank" path="/jsp/ideas/blank.jsp" redirect="false"/> <forward name="Logon" path="/jsp/ideas/LogonSuccess.jsp" redirect="false"/> <forward name="Logout" path="/jsp/ideas/LogoutSuccess.jsp"/>
</action-mappings> [ April 22, 2004: Message edited by: The BigBarber ]
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
5
posted
0
Hello "Barber", I asked you once already, but I guess you didn't see that message -- your display name does not conform to our naming policy so you need to change it. Thank you.
Seems some problem with ur action class extending DispatchAction because basically this DispatchACtion will be used when u want to call the different methods of the same action class depending on some query string r the parameter attribute of ur <action> tag. So some conflict happening with these i feel once make that Action instead of DispatchAction and see....... Regards Sreenath