博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小案例:struts1.3利用nested标签使用POJO
阅读量:6911 次
发布时间:2019-06-27

本文共 3038 字,大约阅读时间需要 10 分钟。

其中的关键就是这个POJO是你自己去new一个,struts是不会帮你创建的!参考http://luohua.iteye.com/blog/39976

表单页

<%@ page language="java" contentType="text/html; charset=GBK"    pageEncoding="GBK"%><%@ 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" %><%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>
Insert title here
INFO:
姓名:
年龄:

ActionForm

public class UseBeanForm extends ActionForm {        private Person person = new Person(); // You must initialize this bean by yourself!!!    private String info;    public String getInfo() {        return info;    }    public Person getPerson() {        return person;    }    public void setInfo(String info) {        this.info = info;    }    public void setPerson(Person person) {        this.person = person;    }    @Override    public ActionErrors validate(ActionMapping mapping,            HttpServletRequest request) {        ActionErrors errors = new ActionErrors();        if (info == null || info.trim().length() == 0) {            errors.add("emptycontent", new ActionMessage("jwid.c14.section14dot5.emptyconent"));        }        if (person == null || person.getName().trim().length() == 0 || person.getAge() <= 0) {            errors.add("emptycontent", new ActionMessage("jwid.c14.section14dot5.emptyconent"));        }        return errors;    }}

Action

public class UseBeanAction extends Action {    @Override    public ActionForward execute(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response)            throws Exception {        UseBeanForm useBeanForm = (UseBeanForm)form;        String info = useBeanForm.getInfo();        if (info.length() > 5) {            return mapping.findForward("infoMore");        } else {            return mapping.findForward("infoLess");        }    }}

结果页1 info_less.jsp

<%@ page language="java" contentType="text/html; charset=GBK"    pageEncoding="GBK"%><%@ 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" %>
Insert title here info.length <= 5
${requestScope.info }
${requestScope.person.name }
${requestScope.person.age }

结果页2 info_more.jsp

<%@ page language="java" contentType="text/html; charset=GBK"    pageEncoding="GBK"%><%@ 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" %>
Insert title here info.length > 5
${requestScope.info }
${requestScope.person.name }
${requestScope.person.age }

struts-config.xml

 

转载地址:http://oaycl.baihongyu.com/

你可能感兴趣的文章
五个免费的轻量级Linux发行版
查看>>
C# GDI+绘制矩形圆角
查看>>
C# DataTable常用操作总结 (转载)
查看>>
还原virtual函数的本质-----C++
查看>>
《GK101任意波发生器》升级固件发布(版本:1.0.2build306)
查看>>
hug and Compression Resistance
查看>>
sql server 2008分页
查看>>
lintcode:Pow(x, n)
查看>>
WebService中使用Aspose.Cells.dll
查看>>
Android菜鸟的成长笔记(28)——Google官方对Andoird 2.x提供的ActionBar支持
查看>>
【转载】装饰模式与代理模式的区别
查看>>
Persona——Web人物角色介绍
查看>>
一个三年工作经验的软件工程师的经验之谈
查看>>
Keepalived+Redis高可用部署(第二版)
查看>>
理解Linux中断 (3)【转】
查看>>
3 hql语法及自定义函数(含array、map讲解) + hive的java api
查看>>
欢迎各位技术牛人增加Swift QQ群:343549891
查看>>
Linux使用imagemagick的convert命令压缩图片、节省服务器空间
查看>>
selenium测试(Java)-- 显式等待(九)
查看>>
MySQL 5.7 mysqlpump 备份工具说明
查看>>