其中的关键就是这个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. Xilinx Spartan6常用资源Verilog例化

    // DSP48A1 : In order to incorporate this function into the design, // Verilog : the following insta ...

  2. python3将docx转换成pdf,html文件,pdf转doc文件

    直接上代码 # -*- encoding:utf-8 -*- """ author:lgh 简单的doc转pdf,html,pdf转doc脚本 依赖库pdfminer3k ...

  3. python利用os和getopt实现删除指定文件

    工作中经常遇到要删除某些目录下的特定文件 例如删除xxx目录下的所有test开头文件或者.pyc结尾的文件 如果手动删除的话,很麻烦,写个程序自动删除 只需要运行的时候输入路径和文件名即可,不输入文件 ...

  4. SparkSQL之更改表结构

    本文篇幅较短,内容源于自己在使用SparkSQL时碰到的一个小问题,因为在之后的数据处理过程中多次使用,所以为了加深印象,在此单独成文,以便回顾. 场景 在使用SparkSQL进行数据处理时,碰到这样 ...

  5. redhat6.3 找不到libXP.so.6解决方法

    最近做redhat安装matlab2008a 操作,遇到上面的问题,先记录如下: 网上找到安装包:libXp-1.0.2-1mamba.x86_64.rpm 然后使用命令: sudo rpm -ivh ...

  6. install.Android

    It was not possible to complete an automatic installation. This might be due to a problem with your ...

  7. zabbix乱码问题

    Zabbix页面遇到历史记录的乱码需要修改数据库: 解决办法: 1.将 zabbix 数据库中的表备份: 2.手动删除 zabbix 数据库: 3.重新创建 zabbix 库时手动指定字符集为 utf ...

  8. idea中git从码云克隆项目到本地

    1.首先需要在操作系统上安装Git分布式管理系统 此处自行百度............. 2.在Intellij IDEA中配置Git 打开Settings(File-->Settings) - ...

  9. iOS_Objective-C測试

    1. iOS中程序正常载入UIViewControlle时,下面四个方法哪个最先运行? A.viewVillAppear B.viewDidLoad C.viewDidAppear D.viewWil ...

  10. 算法笔记_101:蓝桥杯练习 算法提高 身份证号码升级(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 从1999年10月1日开始,公民身份证号码由15位数字增至18位.(18位身份证号码简介).升级方法为: 1.把15位身份证号码中的年份由 ...