小案例:struts1.3利用nested标签使用POJO
其中的关键就是这个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 <= 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 > 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的更多相关文章
- JSONP跨域访问百度实现搜索提示小案例
一.JSONP简介 JSONP 全称 JSON with padding(填充式 JSON 或参数式 JSON),JSONP实现跨域请求的原理,就是动态创建<script>标签,然后利用& ...
- Vue.js小案例、生命周期函数及axios的使用
一.调色框小案例: 随着三个滑动框的变化,颜色框的颜色随之改变 1.1.实例代码 <!DOCTYPE html> <html lang="en" xmlns:v- ...
- 02SpringMvc_springmvc快速入门小案例(XML版本)
这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC. 先给出整个项目的结构图:
- jquery mobile小案例
---恢复内容开始--- [jquery mobile小案例]效果图如下: 首先先创建一个页面主要使用data-role="page"这个指令,我们给它起个id="pag ...
- MVC 小案例 -- 信息管理
前几次更新博客都是每次周日晚上到周一,这次是周一晚上开始写,肯定也是有原因的!那就是我的 Tomact 忽然报错,无法启动,错误信息如下!同时我的 win10 也崩了,重启之后连 WIFI 的标志也不 ...
- Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例
Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例 继上篇json解析,我用了原生的json解析,但是在有些情况下我们不得不承认,一些优秀的json解析框架确实十分的 ...
- (24/24) webpack小案例--自己动手用webpack构建一个React的开发环境
通过前面的学习,对webpack有了更深的认识,故此节我们就利用前面相关知识自己动手用webpack构建一个React的开发环境,就算是一个小案例吧. 注:此处使用的开发工具是Webstorm. 1. ...
- node.js(小案例)_实现学生信息增删改
一.前言 本节内容主要对小案例做一个总结: 1.如何开始搭建小项目 2.路由设计 3.模块应用 4.项目源码以及实现过程github地址: 项目演示如下: 二.主要内容 1.项目的关键性js源码: 项 ...
- WEB 小案例 -- 网上书城(四)
针对于这个小案例我们今天讲解结账操作,也是有关这个案例的最后一次博文,说实话这个案例的博文写的很糟糕,不知道该如何去表述自己的思路,所以内容有点水,其实说到底还是功力不够. 处理思路 点击结账,发送结 ...
随机推荐
- RTP/RTCP、TCP、UDP、RTMP、RTSP
OSI中的层 功能 TCP/IP协议族 应用层 文件传输,电子邮件,文件服务,虚拟终端 TFTP,FTP,HTTP,SNMP,SMTP,DNS,RIP,Telnet 表示层 数据格式化,代码转换,数据 ...
- pgsql常用命令
连接数据库, 默认的用户和数据库是postgres psql -U user -d dbname 切换数据库,相当于mysql的use dbname \c dbname 列举数据库,相当于mysql的 ...
- netmap 编译
参考博客:http://www.cnblogs.com/ruo-yu/p/5083290.html 我用的内核版本是4.4.39 step 1:编译内核. step 2:根据参考博客并没有成功编译出我 ...
- iOS 使用腾讯地图显示用户位置注意事项
1. 向 target中info 加入 NSLocationWhenInUseUsageDescription,string 类型.值是描写叙述为什么须要用户位置,这句话会出如今 提示用户是否同意a ...
- vs2017 自定义生成规则 错误 MSB3721 命令 ”已退出,返回代码为 1。
错误 MSB3721 命令 ”已退出,返回代码为 1. 解决办法:去掉yasm复选框,改为masm vs2017 自定义生成规则-编译汇编代码 VC++调用yasm编译汇编代码有三种方法:Custom ...
- Android,TextView的所有属性和方法
XML 属性 属性名称 相关方法 描述 android:autoLink setAutoLinkMask(int) 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接. ...
- ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value:
今天碰到一个相当棘手的问题,那就是ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value . 本来在本地测试是没有任 ...
- vue - v-text 和 v-html
1.官方有了{{data}}绑定数据了,为啥还要v-text 因为网络问题,可以我们会卡到看“{{}}”,很尴尬吧!!! => 因此推荐用v-text 2. v-html是啥? 能吃吗 , v- ...
- 软件测试中LoadRunner函数中的几个陷阱
软件测试 中 LoadRunner 函数中的几个陷阱 1.atof 在 loadrunner 中如果直接用 float f; f=atof("123.00"); lr _outpu ...
- 学会使用简单的MySQL操作
第十八章 学会使用简单的MySQL操作 在前面两个章节中已经介绍过MySQL的安装了.可是光会安装还不够.还须要会一些主要的相关操作.当然了,关于MySQL的内容也是非常多的.仅仅只是对于linux系 ...