|
(5) SubmitAction.java file
package com.visualbuilder;
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.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages;
public class SubmitAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("Called Submit file "); return mapping.getInputForward(); }
}
(6)Index.jsp file
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html> <html:form action="/validate.do" method="post"> <table> <tr> <td colspan="2"> <logic:messagesPresent> <html:messages id="msg"> <p> <strong><font color="red"><bean:write name="msg" /></font></strong> </p> </html:messages> </logic:messagesPresent> </td> </tr> <tr> <td colspan="2"> <logic:messagesPresent message="true"> <html:messages message="true" id="msg"> <p> <strong><bean:write name="msg" /></strong> </p> </html:messages> </logic:messagesPresent> </td> </tr> <tr><td>Enter the name</td> <td><html:text property="name" /></td></tr> <tr><td> Enter the Phone</td> <td> <html:text property="phone" /></td></tr> <tr><td> Enter the Email</td> <td><html:text property="email" /></td></tr> </table><html:submit>Submit </html:submit> </html:form>
</html:html>
(7)Output
Note:- Whenever the request is submitted to the application you see two line Before Handling Request and After Handling Request printing on the console and the line Called Submit file is printed in between. This shows that for every request the code of CustomActionServlet gets called.
|