*. Properties configure JSP. Hello. Title = Hello world !!!! JSP. Hello. Error = This is error!
Actionform
package com.yourcompany.struts.form; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class HelloForm extends ActionForm { private String userName; public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors=new ActionErrors(); if((userName==null)||(userName.length()<1)) { errors.add("userName",new ActionError("jsp.hello.error")); } return errors; } public void reset(ActionMapping mapping, HttpServletRequest request) { this.userName=null; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } }
Action adds a mapping package COM. yourcompany. struts. action; 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 COM. yourcompany. struts. form. helloform; public class helloaction extends action {
Public actionforward execute (actionmapping mapping, actionform
Form, httpservletrequest request,
Httpservletresponse response) {helloform = (helloform) form; // todo auto-
Generated method stub Return Mapping. findforward ("hello ");}}
JSP <% @ page Language = "Java" pageencoding = "ISO-8859-1" %> <% @ taglib uri = "http://jakarta.apache.org/struts/tags-bean"
Prefix = "Bean" %> <% @ taglib uri = "http://jakarta.apache.org/struts/tags-html" prefix = "html" %> <HTML>
Property = "username"/> <HTML: errors property = "username"/> <br/> <HTML: Submit/> <HTML: cancel/>