Step1:create a index.jsp program and given the
Action Class url pattern
<form action="r.do">
Name:<input type="text"
name="uname"><br></br>
Password:<input type="password"
name="pwd"><br></br>
Address:<input type="textarea"
name="address"><br></br>
<input type="submit" value="Register">
</form>
Step2: develop a Action class and create
DynaValidatorForm class Object and it used for fetching the values from Form
and it is forwared to success page using findForward()me thod
package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import
org.apache.struts.validator.DynaValidatorForm;
public class DynaregisterAction extends
org.apache.struts.action.Action {
private static final String SUCCESS = "success";
public
ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaValidatorForm dvf=(DynaValidatorForm)form;
String
name=(String)dvf.get("uname");
String pwd=(String)dvf.get("pwd");
String address=(String)dvf.get("address");
request.setAttribute("name",name);
return mapping.findForward(SUCCESS);
}
}
step3:it is the configuration of action class
and DynaValidatorForm .
Here,we can configure the <form-property name="" >must and should matched with given form name property.(index.jsp form name attributes mandatory....)
<!-- =============== This is for DynaValidatorForm===============================-->
<form-beans>
<form-bean name="register"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="uname"
type="java.lang.String"/>
<form-property name="pwd"
type="java.lang.String"/>
<form-property name="address"
type="java.lang.String"/>
</form-bean>
</form-beans>
<!-- =============== This is for Action class===============================-->
<action-mappings>
<action path="/r" name="register"
type="controller.DynaregisterAction">
<forward name="success" path="/success.jsp"/>
</action>
<action path="/Welcome"
forward="/welcomeStruts.jsp"/>
</action-mappings>
Step4:developa success page success.jsp page
It is geeting the name using request scope
Hi!<%=request.getAttribute("name")%>
<br></br>
You are success fully registerd
...<br></br>
<a href="index.jsp"> Add</a>
Result:
After entering data into form
0 comments:
Post a Comment