action class is not executing in struts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shanmukhi
    New Member
    • Jan 2007
    • 58

    #1

    action class is not executing in struts

    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(Str ing password) {
    this.password = password;
    }

    public String getUsername() {
    return username;
    }

    public void setUsername(Str ing username) {
    this.username = username;
    }
    public void reset(ActionMap ping mapping, HttpServletRequ est request) {
    this.username=n ull;
    this.password=n ull;


    }
    }
    [/CODE}
    ActionLogin.jav a
    Code:
    public class ActionLogin extends Action {
    public ActionForward execute(HttpServletRequest req, HttpServletResponse res,
    		ActionForm form, ActionMapping mapping)throws Exception
    {
    	System.out.println("this is action class");
    	FormLogin fl=(FormLogin)form;
    	System.out.println(fl.getUsername());
    	System.out.println(fl.getPassword());
    	return mapping.findForward("success");
    	}
    }
    login.jsp
    Code:
    <html:form action="/login">
    <html:text property="username">username</html:text>
    <html:password property="password">password</html:password>
    <html:submit>submit</html:submit>
    </html:form>
    struts-cfg.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
     
       <form-beans>
       <form-bean
    name="FormLogin"
    type="com.yourcompany.struts.FormLogin"/>
    
    
    </form-beans>
    
       <global-exceptions />
    
       <action-mappings>
       <action
         path="/login"
         type="com.yourcompany.struts.ActionLogin"
         name="FormLogin"
         scope="request"
         validate="true"
         input="/Pages/login.jsp">
          <forward name="success" path="/Pages/Success.jsp"/>
    </action>
    </action-mappings>
       <message-resources parameter="com.yourcompany.struts.AppllicationResources" />
    </struts-config>
    Success.jsp page has
    Code:
    <body>
    success fully login
    </body>
    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...
  • sumittyagi
    Recognized Expert New Member
    • Mar 2007
    • 202

    #2
    I don't know much about struts, but I think your problem lies here:
    Code:
    <html:password property="password">password</html:password>
    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:
    Code:
    <input type="password" name="password" />
    .

    rename it to pwd or password1 or userPassword etc.
    Code:
    <html:password property="userPassword">password</html:password>

    Comment

    • pavancognizant
      New Member
      • May 2007
      • 7

      #3
      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.d o">


      Originally posted by sumittyagi
      I don't know much about struts, but I think your problem lies here:
      Code:
      <html:password property="password">password</html:password>
      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:
      Code:
      <input type="password" name="password" />
      .

      rename it to pwd or password1 or userPassword etc.
      Code:
      <html:password property="userPassword">password</html:password>

      Comment

      • shanmukhi
        New Member
        • Jan 2007
        • 58

        #4
        Originally posted by sumittyagi
        I don't know much about struts, but I think your problem lies here:
        Code:
        <html:password property="password">password</html:password>
        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:
        Code:
        <input type="password" name="password" />
        .

        rename it to pwd or password1 or userPassword etc.
        Code:
        <html:password property="userPassword">password</html:password>

        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
        Code:
        execute(
        	ActionMapping mapping,	ActionForm form, HttpServletRequest request, 
        		HttpServletResponse response)

        Comment

        Working...