Struts review 1 (animation)

Source: Internet
Author: User

*. 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/>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.