Saturday, May 8, 2010

Struts Application-dynaActionForm

Struts Application-Actionform-DynaActionForm.

Purpose:
             No need to create actionform explicitly.

            We made some change in Struts-config.xml file
             under WEB-INF


Procedure:

Step_1:

Add Properties into Struts-config.xml file.

< form-beans >

< form-bean name="loginform" type="org.apache.struts.action.DynaActionForm" / >
< form-property name="password" type="java.lang.String" / >
< form-property name="username" type="java.lang.String" / >
< /form-bean >

< /form-beans >


Step_2:

Create action class.

Include code below

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{

DynaActionForm sform=(DynaActionForm)form;

if((sform.get("username")).equals("suresh"))
{
return mapping.findForward("one");
}
else
{
return mapping.findForward("two");
}

}
















Step_3:

          Configure Struts.config.xml



Step_4:

Creating dyna.jsp

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
< html/ >
< head > < title > JSP Page < /title > < /head >
< body >
< html:form action="/dyna" >
< html:text property="username"/ >
< html:password property="password" / >
< html:submit/ >
< /html:form >
< /body
< /html >





Step_5:

Creating one.jsp and two.jsp

One.jsp

< html >
< head > < title > One jsp < /title > > / head <
< body >
Welcome One .jsp
< / body >
< / html >

two.jsp

< html >
< head > < title > One jsp < /title > > / head <
< body >
Welcome One .jsp
< / body >
< / html >


Step_6:

          Run the dyna.jsp




You give username as suresh , the one.jsp file will be executed, otherwise the two.jsp file will be executed.

you give sureshs as username You get



Conclusion:

We have seen dynaActionForm class. if It is not necessary to create

actionform explicitly. when we use dynaActionForm.

No comments:

Post a Comment