By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

action class is not executing in struts

P: 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...
May 31 '07 #1
Share this Question
Share on Google+
3 Replies


sumittyagi
Expert 100+
P: 202
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.  
May 31 '07 #2

P: 7
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">


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.  
May 31 '07 #3

P: 58
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.  
Jun 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.