Struts Application-cancel() method
Aim:
Sometimes the user or client want to cancel the operation, Struts Framework provide special html tag to perform this operation.
Procedure:
Step_1:
Include < html:cancel / > tag into any jsp file.
Step_2:
Include actionforms I have used cancelForm as actionforms.
package actionforms;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class cancelForm extends org.apache.struts.action.ActionForm
{
private String Name;
public String getName()
{
return Name;
}
public void setName(String Name)
{
this.Name = Name;
}
}
Step_3:
Create Action class I have named as cancelAction
Include following programming code.
package actions;
import actionforms.cancelForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
public class cancelAction extends org.apache.struts.action.Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
if(isCancelled(request))
{
return mapping.findForward("home");
}
cancelForm sform=(cancelForm)form;
request.setAttribute("name",sform.getName());
return mapping.findForward("welcome");
}
}
Step_:4
Creating jsp files.
cancel.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="/cancel" >
< html:text property="name"/ >
< html:submit/ > < html:cancel value="ignore"/ >
< /html:form >
< /body >
< /html >
Step_5:
Creating home.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 >
Hello! This is Home
< /body >
< /html >
Step_6:
Creating welcome.jsp
< html >
< head > < title > JSP Page < /title > < /head >
< body >
Welcome:< %= request.getAttribute(“name”) % >
< /body >
< /html >
Step_7:
Configure Struts-config.xml
Step_8:
Run the cancel.jsp file.
If you click cancel button the control gose to home.jsp.
Otherwise the control goes to welcome.jsp
Conclusion:
From This Post We understood how to perform cancel operation.
The action handler check the iscancelled() method is execute, if it was inside the block will execute.
Do You Have Any Query
Post Comments
No comments:
Post a Comment