其中的关键就是这个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. 使用Apache POI导出Excel小结--导出XLS格式文档

    使用Apache POI导出Excel小结 关于使用Apache POI导出Excel我大概会分三篇文章去写 使用Apache POI导出Excel小结--导出XLS格式文档 使用Apache POI ...

  2. 二十四种设计模式:策略模式(Strategy Pattern)

    策略模式(Strategy Pattern) 介绍定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换.本模式使得算法的变化可独立于使用它的客户. 示例有一个Message实体类,对它的操作有 ...

  3. mysql重置密码和mysql error 1044(42000)错误

    #mysql错误:(密码不正确,需要重置密码) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...

  4. Android视图SurfaceView的实现原理分析(示例,出错代码)

    在Android系统中,有一种特殊的视图,称为SurfaceView,它拥有独立的绘图表面,即它不与其宿主窗口共享同一个绘图表面.由于拥有独立的绘图表面,因此SurfaceView的UI就可以在一个独 ...

  5. 从外部重置一个运行中consumer group的消费进度

    对于0.10.1以上版本的kafka, 如何从外部重置一个运行中的consumer group的进度呢?比如有一个控制台,可以主动重置任意消费组的消费进度重置到12小时之前, 而用户的程序可以保持运行 ...

  6. 阅读源代码的重要性:如厨师选食材,耍厨具——在Eclipse中怎样查看Java、Android源代码

    首先,非常多人说,不会看jdk中的源代码就不叫学过Java.显然这是肯定的.打个例如:真正的厨师须要从食材的选取.加工.到最后的烹饪.装盘成型,甚至到最后给用户介绍食用方法等一整套流程走下来.而实际上 ...

  7. Java基础大家必看啊

    写代码: 1,明确需求.我要做什么? 2,分析思路.我要怎么做?1,2,3. 3,确定步骤.每一个思路部分用到哪些语句,方法,和对象. 4,代码实现.用具体的java语言代码把思路体现出来.   学习 ...

  8. 2014面试总结--java、数据 方向

    这里不讲详细的题目.仅仅是总结一下体会. 好一点的公司考察的都比較全面,主要看你对原理性的理解.还有你的思维逻辑:就眼下来讲,对深度的考察大于广度.而我个人如今这个阶段也比較专注于深度. 列一些常常问 ...

  9. 利用U盘启动,全新安装Mac操作系统.

    利用U盘启动,全新安装Mac操作系统. OS_X_Yosemite_DP7.dmg Install OS X Yosemite.dmg 简单制作 OS X Yosemite 10.10 正式版U盘US ...

  10. 在k8s中的基本概念

    在k8s中的基本概念 一.Pod1. podk8s下最重要也最基本的概念,由一个根容器Pause和许多用户业务容器组成,是容器的载体. 2. pod的yaml定义格式及字段 apiVersion: v ...