File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts Action problem immediate please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Action problem immediate please" Watch "Struts Action problem immediate please" New topic

Struts Action problem immediate please

Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
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<p>Great minds discuss ideas. Average minds discuss events. Small minds discuss people.
The BigBarber

Joined: Mar 30, 2004
Posts: 9
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
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

vasantha prabh
The BigBarber

Joined: Mar 30, 2004
Posts: 9
can you post your code then it can be corrected.
Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
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");
return mapping.findForward(Constants.SUCCESS);
The BigBarber

Joined: Mar 30, 2004
Posts: 9
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.
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();
return mapping.findForward("Logon");
bean BEAN = new bean();
}catch(Exception e){System.out.println(e);}
return mapping.findForward("LogonError");
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");;
int index = Integer.parseInt(rs.getString(1));
stmt.executeUpdate("insert into struts_index values ("+ ++index +",'"+name+"')");
A Part of my Struts-Config.xml Contains the following.
<!-- ========== Form Bean Definitions =================================== -->
<form-bean name="Logon"
<!-- ========== Global Forward Definitions ============================== -->
<forward name="Blank"
<forward name="Logon"
<forward name="Logout"

<forward name="LogonError"
<forward name="Login"

<!-- ========== Action Mapping Definitions ============================== -->
<action path="/Logon"

<action path="/Logout"


[ April 22, 2004: Message edited by: The BigBarber ]
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
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.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415

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.......
I agree. Here's the link:
subject: Struts Action problem immediate please
It's not a secret anymore!