Connecting Tech Pros Worldwide Help | Site Map

action class is not executing in struts

  #1  
Old May 31st, 2007, 12:49 PM
Member
 
Join Date: Jan 2007
Posts: 58
hi all,
i got a problem with struts.
iam unable to find it.
i have written an action class, form bean class and a jsp page
on submitting form, request is going to action class but it is not executing action class iam unable to solve it...
here is my code
FormLogin.java
[code]
public class FormLogin extends ActionForm{
private String username=null;;
private String password=null;;

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.username=null;
this.password=null;


}
}
[/CODE}
ActionLogin.java
Expand|Select|Wrap|Line Numbers
  1. public class ActionLogin extends Action {
  2. public ActionForward execute(HttpServletRequest req, HttpServletResponse res,
  3.         ActionForm form, ActionMapping mapping)throws Exception
  4. {
  5.     System.out.println("this is action class");
  6.     FormLogin fl=(FormLogin)form;
  7.     System.out.println(fl.getUsername());
  8.     System.out.println(fl.getPassword());
  9.     return mapping.findForward("success");
  10.     }
  11. }
  12.  
  13.  
login.jsp
Expand|Select|Wrap|Line Numbers
  1. <html:form action="/login">
  2. <html:text property="username">username</html:text>
  3. <html:password property="password">password</html:password>
  4. <html:submit>submit</html:submit>
  5. </html:form>
  6.  
struts-cfg.xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
  3. <struts-config>
  4.  
  5.    <form-beans>
  6.    <form-bean
  7. name="FormLogin"
  8. type="com.yourcompany.struts.FormLogin"/>
  9.  
  10.  
  11. </form-beans>
  12.  
  13.    <global-exceptions />
  14.  
  15.    <action-mappings>
  16.    <action
  17.      path="/login"
  18.      type="com.yourcompany.struts.ActionLogin"
  19.      name="FormLogin"
  20.      scope="request"
  21.      validate="true"
  22.      input="/Pages/login.jsp">
  23.       <forward name="success" path="/Pages/Success.jsp"/>
  24. </action>
  25. </action-mappings>
  26.    <message-resources parameter="com.yourcompany.struts.AppllicationResources" />
  27. </struts-config>
  28.  
  29.  
Success.jsp page has
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. success fully login
  3. </body>
  4.  
login.jsp and Success.jsp pages are in pages folder of webroot.
when i send request to login.jsp form was displayed but when i will submit the form it is not going to success.jsp blank page is coming..
the request will be like this when i submit form
http://localhost:8080/StrutsApp/login.do
how can i solve it...
  #2  
Old May 31st, 2007, 01:31 PM
sumittyagi's Avatar
Expert
 
Join Date: Mar 2007
Location: New Delhi, India
Posts: 198

re: action class is not executing in struts


I don't know much about struts, but I think your problem lies here:
Expand|Select|Wrap|Line Numbers
  1. <html:password property="password">password</html:password>
  2.  
It would be a javascript problem. don't give reserved words names to your variables.
I think the above statement will be generating the equivalient in html:
Expand|Select|Wrap|Line Numbers
  1. <input type="password" name="password" />
  2.  
.

rename it to pwd or password1 or userPassword etc.
Expand|Select|Wrap|Line Numbers
  1. <html:password property="userPassword">password</html:password>
  2.  
  #3  
Old May 31st, 2007, 02:16 PM
Newbie
 
Join Date: May 2007
Posts: 7

re: action class is not executing in struts


whats the mapping of action in your web.xml if its *.do then put login.do in your action attribute of html form tag..... and also see if there is any exception in your server console....

<html:form action="login.do">


Quote:
Originally Posted by sumittyagi
I don't know much about struts, but I think your problem lies here:
Expand|Select|Wrap|Line Numbers
  1. <html:password property="password">password</html:password>
  2.  
It would be a javascript problem. don't give reserved words names to your variables.
I think the above statement will be generating the equivalient in html:
Expand|Select|Wrap|Line Numbers
  1. <input type="password" name="password" />
  2.  
.

rename it to pwd or password1 or userPassword etc.
Expand|Select|Wrap|Line Numbers
  1. <html:password property="userPassword">password</html:password>
  2.  
  #4  
Old June 1st, 2007, 06:59 AM
Member
 
Join Date: Jan 2007
Posts: 58

re: action class is not executing in struts


Quote:
Originally Posted by sumittyagi
I don't know much about struts, but I think your problem lies here:
Expand|Select|Wrap|Line Numbers
  1. <html:password property="password">password</html:password>
  2.  
It would be a javascript problem. don't give reserved words names to your variables.
I think the above statement will be generating the equivalient in html:
Expand|Select|Wrap|Line Numbers
  1. <input type="password" name="password" />
  2.  
.

rename it to pwd or password1 or userPassword etc.
Expand|Select|Wrap|Line Numbers
  1. <html:password property="userPassword">password</html:password>
  2.  

Thank u for your reply

but that is not the problem with my code..
i solved it.
the problem is with parameters of execute method in action class
i changed the sequence of parameters in the execute method..

The sequence should be
Expand|Select|Wrap|Line Numbers
  1. execute(
  2.     ActionMapping mapping,    ActionForm form, HttpServletRequest request, 
  3.         HttpServletResponse response)
  4.  
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
how J2EE framework works????? dmjpro answers 3 February 18th, 2009 03:03 PM