Simple data verification of Struts2

Source: Internet
Author: User

First, you must add the statement in the class corresponding to the ACTION, for example:
Do you want to write this. addFieldErrZ into T. java? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcig =" name "," name is error ");, add a name attribute with the content name is error.

package com.xjtu.st;import com.opensymphony.xwork2.ActionSupport;import com.xjtu.dto.DTOStudent;import com.xjtu.vo.Student;public class T extends ActionSupport {String name;public String exe() {System.out.println(name);if (name == null || !name.equals("yangzhi")) {this.addFieldError("name", "name is error");return "error";}return "aaa";}public String getName() {return name;}public void setName(String name) {this.name = name;}}
Configure the struts tag on the page to jump.
<%@ taglib uri="/struts-tags" prefix="s" %>
Write in the BODY of HTML
    
 // Check
 // The system automatically enters the information you saved
 // This tag is the value in ValueStack, which has many attributes. errors is one of them.
//
  Errors is a map, which extracts all key-value pairs
//
   Errors. name is a string array. This sentence is all the content in the output, because it can contain a lot of information in name.
//
    Retrieve the nth Value
S Delete student

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.