• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts Action problem immediate please

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you post your code then it can be corrected.
 
Vasantha Prabha
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"/>

<forward name="LogonError"
path="/jsp/ideas/LogonError.jsp"/>
<forward name="Login"
path="/login.jsp"/>

</global-forwards>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<action path="/Logon"
type="ideas.LogonAction"
name="Logon"
input="/jsp/ideas/Logon.jsp"
scope="session"/>

<action path="/Logout"
type="ideas.LogoutAction"
name="Logon"
scope="request"/>

</action-mappings>

[ April 22, 2004: Message edited by: The BigBarber ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic