Struts Tutorial Home

Struts Home

JSP Resources

Community

Site

(3) Validator Form file


package com.visualbuilder;


import org.apache.struts.validator.ValidatorForm;


 


public class InputForm extends ValidatorForm {


    String name;


    String email;


    String phone;


    public String getEmail() {
        return email;
        }


    public void setEmail(String email) {
        this.email = email;
        }


    public String getName() {
        return name;
        }


    public void setName(String name) {
        this.name = name;
        }


    public String getPhone() {
        return phone;
        }


    public void setPhone(String phone) {
        this.phone = phone;
        }
    }


 


(3) Validator Action 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;


public class ValidateAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception {
        return mapping.getInputForward();
    }


}


(4) 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>

                    

Copyright © 2013 VisualBuilder. All rights reserved