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 ...
随机推荐
- noip 2013 提高组 day1
1.转圈游戏: 解析部分略,快速幂就可以过 Code: #include<iostream> #include<fstream> using namespace std; if ...
- git download error processing
git clone git@github.com:happyfish100/fastdfs.git 提示下列信息: Warning: Permanently added 'github.com,192 ...
- HTTP协议请求类型介绍
HTTP协议中共定义了八种方法或者叫"动作"来表明对Request-URI指定的资源的不同操作方式,具体介绍如下: OPTIONS: 返回服务器针对特定资源所支持的HTTP请求方法 ...
- 搭建git 服务器
Gogs 什么是 Gogs? Gogs 是一款极易搭建的自助 Git 服务. https://gogs.io/docs
- 数据集是 seq 文件的处理办法
数据集是 seq 文件的处理办法 2017-03-17 最近下了一个数据集,是 seq 格式的,第一次处理这种数据.使用了官方提供的 matlab 工具包:https://pdollar.github ...
- WEB 安全学习 一、mysql 注入漏洞
转载: https://www.cnblogs.com/cui0x01/p/8620524.html 一.Mysql数据库结构 数据库A 表名 列名 数据 数据库B 表名 列名 数据 Mysql5.0 ...
- Luncene学习二《搜索索引》
搜索索引的流程 第一步:创建一个Directory对象,也就是索引库存放的位置 第二步:创建一个IndexReader对象,需要指定Directory对象 第三步:创建一个indexsearcher对 ...
- Luncene学习 第一天 《入门程序》
整个luncene 流程 下面贴出代码 package com.zuoyan.lucene.demo; import java.io.File; import org.apache.commons.i ...
- Gym 100247B Similar Strings(哈希+思维)
https://vjudge.net/problem/Gym-100247B 题意: 如果两个字符串通过映射后是一样的,则说明这两个字符串是相似的,现在给出n个字符串,计算出有多少组字符串是相似的. ...
- ADO.NET DBHelper
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Da ...