标签:list 并且 image efault publish dtd apach shu 应该
public class BookAction extends ActionSupport {
private Book book;
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public String add() {
return SUCCESS;
}
public void validateAdd() {//validateXxx()格式
if (book.getBookName().isEmpty()) {
addFieldError("book.bookName", "书名不能为空!");
}
if (book.getBookPrice()<=0) {
addFieldError("book.bookPrice", "单价不应小于等于0");
}
if (book.getBookPublishDate() == null||book.getBookPublishDate().after(new Date())) {
addFieldError("book.bookPublicDate", "出版日期不能为空并且应该在今天之前!");
}
if (book.getBookCount() <= 0) {
addFieldError("book.bookCount", "数量应大于0");
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="addBook" class="com.example.action.BookAction" method="add">
<result>/addBook.jsp</result>
<result name="input">/addBook.jsp</result>
</action>
</package>
</struts>
使用validateXxx()方法进行输入校验 --Struts2框架
标签:list 并且 image efault publish dtd apach shu 应该
原文地址:https://www.cnblogs.com/qikeyishu/p/9215281.html