Struts2框架之类型转换 --Struts2框架
Struts2框架实现了大多数常见的用于类型转换的转换器,开发人员不用自己编写类型转换代码,就可以实现数据类型的转换。下面一个Struts2框架类型转换的简单事例,
本例可在使用validate()方法进行输入校验 --Struts2框架基础上进行修改。
1、修改BookAction.java:
public class BookAction extends ActionSupport {
private Book book;
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public String execute() {
if (book == null || book.getBookName().isEmpty()) {
addActionError("请输入完整的数目信息!");
return INPUT;
} else {
System.out.println("添加的书目信息如下:");
System.out.println("书名:" + book.getBookName());
System.out.println("单价:" + book.getBookPrice());
System.out.println("出版日期:" + book.getBookPublishDate());
System.out.println("数量:" + book.getBookCount());
return SUCCESS;
}
}
}
2、修改addBook.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'addBook.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<s:actionerror />
<s:form action="addBook">
<s:textfield name="book.bookName" label="书名" />
<s:textfield name="book.bookPrice" label="单价" />
<s:textfield name="book.bookPublishDate" label="出版日期" />
<s:textfield name="book.bookCount" label="数量" />
<s:submit value="提交" />
<s:reset value="重置" />
</s:form>
<s:if test="book.bookName != ''">
添加的书目信息如下:<br>
书名:<s:property value="book.bookName" />
<br>
单价:<s:property value="book.bookPrice" />
<br>
出版日期:<s:property value="book.bookPublishDate" />
<br>
数量:<s:property value="book.bookCount" />
</s:if>
</body>
</html>
3、执行结果

控制台显示类型转换后的信息

Struts2框架之类型转换 --Struts2框架的更多相关文章
- JavaWeb框架_Struts2_(六)----->Struts2的输入校验
1. 输入校验章节目录 输入校验概述 客户端校验 服务器端校验 手动编程校验 重写validate方法 重写validateXxx()方法 输入校验流程 校验框架校验 Struts2 内置的校验器 常 ...
- SSH框架简化(struts2+spring+hibernate)
目的: 通过对ssh框架有了基础性的学习,本文主要是使用注解的方式来简化ssh框架的代码编写. 注意事项: 1.运行环境:Windows 8-64位,Eclipse(开发工具),jdk1.8.0_91 ...
- Struts2,Spring, Hibernate三大框架SSH的整合步骤
整合步骤 创建web工程 引入相应的jar包 整合spring和hibernate框架 编写实体类pojo和hbm.xml文件 编写bean-base.xml文件 <!-- 1) 连接池实例 - ...
- struts2 spring3.2 hibernate4.1 框架搭建 整合
ssh是企业开发中常遇到的框架组合,现将框架的搭建过程记录下来,以便以后查看.我的搭建过程是,首先struts,然后spring,最后hibernate.struts2的最新版本为2.3.8,我下载的 ...
- 第3章 Struts2框架--1、Struts2环境搭建
第3章 Struts2框架--1.Struts2环境搭建 搭建步骤: 1.从下载http://struts.apache.org 没找到Struts2.3.16版,就下载了2.3.29 2.拷贝后解压 ...
- 【SSH框架】之Struts2系列(二)
微信公众号:compassblog 欢迎关注.转发,互相学习,共同进步! 有任何问题,请后台留言联 1.Struts2常量配置 (1).Struts2默认常量配置文件路径,如下图: (2).Strut ...
- Struts2,Spring3,Hibernate4整合--SSH框架
Struts2,Spring3,Hibernate4整合--SSH框架(学习中) 一.包的导入 1.Spring包 2.Hibernate 包 3.struts 包 (还欠 struts2-sprin ...
- SSH框架的简化(struts2、spring4、hibernate5)
目的: 通过对ssh框架有了基础性的学习,本文主要是使用注解的方式来简化ssh框架的代码编写. 注意事项: 1.本文提纲:本文通过一个新闻管理系统的实例来简化ssh框架的代码编写,功能包括查询数据库中 ...
- Struts2框架学习(一)——Struts2的概念及搭建
一.Struts2的概念 使用优势:1)自动封装参数 2)参数校验 3)结果的处理(转发|重定向) 4)国际化 5)显示等待页面 6)防止表单重复提交 Struts2具有更加先进的架构以及思想 Str ...
随机推荐
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- 前端 --- 4 js
一.js 描述 JavaScript 是脚本语言 JavaScript 是一种轻量级的编程语言.后来出现了node.js,可以作为后端语言来开发项目, js是一个既能做前端又能做后端的语言 Java ...
- 使用Selenium+Java+Juint实现移动web端自动化的代码实现
浏览器: Chrome 首先通过developer模式查看Chrome浏览器支持哪些手机,如图: 在代码中使用ChromeOptions对象的addArguments方法来设置参数,如下代码所示: p ...
- LD_RUN_PATH和LD_LIBRARY_PATH是干什么的?
1. 使用场合 LD_RUN_PATH在链接时使用 LD_LIBRARY_PATH在执行时使用 2. 如何指定环境变量 export LD_LIBRARY_PATH=/opt/jello/lib:$L ...
- ununtu 18.04 163 mirror
deb http://mirrors.163.com/ubuntu/ bionic main restricted deb http://mirrors.163.com/ubuntu/ bionic- ...
- P1337 [JSOI2004]平衡点 / 吊打XXX 模拟退火
链接 https://www.luogu.org/problemnew/show/P1337 思路 交了好多发,都是wrong 初始值取平均数就1A了 真的是玄学的算法 代码 // luogu-jud ...
- 外观模式Facade pattern
http://www.runoob.com/design-pattern/facade-pattern.html 外观模式 外观模式(Facade Pattern)隐藏系统的复杂性,并向客户端提供了一 ...
- C# 截取 byte 字节 转字符串
byte[] byteArray = System.Text.Encoding.Default.GetBytes(content); Byte[] ThisByte = new Byte[1];Buf ...
- 深度学习课程笔记(十三)深度强化学习 --- 策略梯度方法(Policy Gradient Methods)
深度学习课程笔记(十三)深度强化学习 --- 策略梯度方法(Policy Gradient Methods) 2018-07-17 16:50:12 Reference:https://www.you ...
- [HDU 2520] 我是菜鸟,我怕谁(不一样的for循环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2520 //学学不一样的for循环 #include<iostream> #include& ...