其中的关键就是这个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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<span style="color:red"><html:errors property="emptycontent"/></span>
<html:form action="/jwid/struts1x/14.5/usebean.do" method="post">
INFO:<html:text property="info"/><br>
<nested:nest property="person">
姓名:<nested:text property="name"/><br>
年龄:<nested:text property="age"/><br>
</nested:nest>
<html:submit value="提交"/><html:reset value="重置"/>
</html:form>
</body>
</html>

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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
info.length &lt;= 5<br>
${requestScope.info }<br>
${requestScope.person.name }<br>
${requestScope.person.age }
</body>
</html>

结果页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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
info.length &gt; 5<br>
${requestScope.info }<br>
${requestScope.person.name }<br>
${requestScope.person.age }
</body>
</html>

struts-config.xml

<form-bean name="useBeanForm"
type="jwid.c14.section14dot5.UseBeanForm" /> <action attribute="useBeanForm" name="useBeanForm" scope="request"
path="/jwid/struts1x/14.5/usebean" input="/jwid/struts1x/14.5/use_bean.jsp"
type="jwid.c14.section14dot5.UseBeanAction">
<forward name="infoMore" path="/jwid/struts1x/14.5/info_more.jsp"/>
<forward name="infoLess" path="/jwid/struts1x/14.5/info_less.jsp"/>
</action>

小案例:struts1.3利用nested标签使用POJO的更多相关文章

  1. JSONP跨域访问百度实现搜索提示小案例

    一.JSONP简介 JSONP 全称 JSON with padding(填充式 JSON 或参数式 JSON),JSONP实现跨域请求的原理,就是动态创建<script>标签,然后利用& ...

  2. Vue.js小案例、生命周期函数及axios的使用

    一.调色框小案例: 随着三个滑动框的变化,颜色框的颜色随之改变 1.1.实例代码 <!DOCTYPE html> <html lang="en" xmlns:v- ...

  3. 02SpringMvc_springmvc快速入门小案例(XML版本)

    这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC. 先给出整个项目的结构图:

  4. jquery mobile小案例

    ---恢复内容开始--- [jquery mobile小案例]效果图如下: 首先先创建一个页面主要使用data-role="page"这个指令,我们给它起个id="pag ...

  5. MVC 小案例 -- 信息管理

    前几次更新博客都是每次周日晚上到周一,这次是周一晚上开始写,肯定也是有原因的!那就是我的 Tomact 忽然报错,无法启动,错误信息如下!同时我的 win10 也崩了,重启之后连 WIFI 的标志也不 ...

  6. Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例

    Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例 继上篇json解析,我用了原生的json解析,但是在有些情况下我们不得不承认,一些优秀的json解析框架确实十分的 ...

  7. (24/24) webpack小案例--自己动手用webpack构建一个React的开发环境

    通过前面的学习,对webpack有了更深的认识,故此节我们就利用前面相关知识自己动手用webpack构建一个React的开发环境,就算是一个小案例吧. 注:此处使用的开发工具是Webstorm. 1. ...

  8. node.js(小案例)_实现学生信息增删改

    一.前言 本节内容主要对小案例做一个总结: 1.如何开始搭建小项目 2.路由设计 3.模块应用 4.项目源码以及实现过程github地址: 项目演示如下: 二.主要内容 1.项目的关键性js源码: 项 ...

  9. WEB 小案例 -- 网上书城(四)

    针对于这个小案例我们今天讲解结账操作,也是有关这个案例的最后一次博文,说实话这个案例的博文写的很糟糕,不知道该如何去表述自己的思路,所以内容有点水,其实说到底还是功力不够. 处理思路 点击结账,发送结 ...

随机推荐

  1. pyqt5生成的APP制作DMG

    http://blog.csdn.net/wudj810818/article/details/70557284 1.环境 Mac OS Python3.5 PyQt5 2.所需工具 Pyinstal ...

  2. [Guava] EventBus

    1.  发布-订阅模式 发布-订阅模式(publish-subscribe)是一种编程范式,发布方不发布消息给特定的接收方,而是由订阅方选择性接收.这使得发布方和订阅方相对独立,减少了耦合性. 在发布 ...

  3. Android检测网络连接

    Android检测网络连接 import android.app.AlertDialog; import android.content.Context; import android.content ...

  4. Android权限操作之uses-permission详解

    本文实例讲述了Android权限操作之uses-permission.分享给大家供大家参考,具体如下: 我们在安装Android软件的时候,系统会提示该软件所需要的权限,相对于其他系统,android ...

  5. Android LayoutInflater布局填充器

    Android LayoutInflater布局填充器 把一份xml布局文件转为View对象,这就是layoutinflater的作用. 对于一个没有被载入或者想要动态载入的界面,都需要使用Layou ...

  6. linux内核设计学习

    负载平衡程序 load_balance调用条件:只要当前可执行队列为空,它就会被调用.被定时器调用:系统空闲时每隔1毫秒调用一次或其他情况下每隔200mm调用一次.单处理器不会被调用 执行步骤1. 首 ...

  7. chkconfig 检查、设置系统的各种服务

    chkconfig 检查.设置系统的各种服务 学习了:http://man.linuxde.net/chkconfig chkconfig --add 某某服务

  8. python 带颜色样式打印到终端

    #!/usr/bin/python # -*- coding: utf-8 -*- """ Created on Tue Aug 8 17:01:54 2017 @aut ...

  9. JS设计模式基础

    设计模式: 通过封装.继承.多态.组合等技术的反复使用,提炼出一些可重复使用的面向对象设计技巧. 1.多态(’做什么‘和’谁去做‘分开) 多态指同一个实体同时具有多种形式. 同一操作应用于不同的对象上 ...

  10. php引用(&)变量引用,函数引用,对象引用和参数引用用法

    php引用(&)变量引用,函数引用,对象引用和参数引用用法   php的引用(就是在变量或者函数.对象等前面加上&符号) 在PHP 中引用的意思是:不同的名字访问同一个变量内容.与C语 ...