Struts2 ——学习笔记7 杂

实体.hbm.xml文件中设置以下属性,作用为能够动态修改

dynamic-insert=true

dynamic-update=true



格式化数据显示:(配置文件)

package.proporties    :

#number  
format.money={0,number,#0.00#}   
#date
date.format={0,date,yyyy-MM-dd HH:mm:ss}

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
  <!--国际化配置 -->
  <constant name="struts.custom.i18n.resources" value="package"/>
  
	<package name="hang" namespace="/" extends="struts-default">
		<!-- 查询所有的商品信息 -->
		<action name="good" class="com.hlx.action.GoodsAction">
			<result>/list.jsp</result>
		</action>
		
		<!-- 下订单 -->
		<action name="add" class="com.hlx.action.GoodsAction" method="add">
			<result>/add.jsp</result>
			<result name="input" type="redirectAction">good.action</result>
		</action>
		
		<!-- 添加订单 -->
		<action name="save" class="com.hlx.action.GoodsAction" method="save">
			<result>/show.jsp</result>
		   <result name="input" type="redirectAction">good.action</result>
		</action>
	</package>
</struts>    

需要格式化的页面:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'show.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">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<style type="text/css">
* {
	font-size: 14px;
}

div {
	width: 1200px;
	margin-left: 20px;
}

li {
	width: 200px;
	list-style: none;
	float: left;
}

table {
	clear: both;;
}

.bd {
	font-weight: bolder;
}

span {
	font-weight: bolder;
	border-bottom: 2px solid black;
}
</style>
</head>

<body>
	<center>
		<div>
			<ul>
				<li>订单号:<span><s:property value="orders.id" /> </span>
				</li>
				<li>收货人:<span><s:property value="orders.name" /> </span>
				</li>
				<li>收货地址:<span><s:property value="orders.address" /> </span>
				</li>
				<li>订单日期:<span><s:text name="date.format">
							<s:param value="orders.createtime"></s:param>
						</s:text> </span>
				</li>
			</ul>
		</div>
		<table border="1" width="85%" height="150">
			<tbody>
				<tr align="center">
					<td> 商品名称</td>
					<td> 价格</td>
					<td> 数量</td>
					<td> 金额</td>
				</tr>
				<s:iterator value="orders.orderitems">
					<tr align="center">
						<td><s:property value="goods.name" /></td>
						<td>¥<s:text name="format.money">
								<s:param value="goods.price"></s:param>
							</s:text>
						</td>
						<td><s:property value="amount" /></td>
						<td>¥<s:text name="format.money">
								<s:param value="goods.price*amount"></s:param>
							</s:text>
						</td>
					</tr>
				</s:iterator>
				<tr align="right">
					<td colspan="4" class="bd">总金额: ¥<s:text name="format.money">
							<s:param value="total"></s:param>
						</s:text></td>
				</tr>
			</tbody>
		</table>
	</center>
</body>
</html>

语言转化:


index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title><s:text name="my.title"/></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">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>

<body>
	<a href="china.action?request_locale=zh_CN">中文</a>
	<a href="china.action?request_locale=en_US">英文</a>
	<a href="china.action?request_locale=zh_TW">台湾</a>

	<s:form action="login" method="post">
		<s:textfield name="uname" key="my.name" />
		<s:password name="upass" key="my.pass" />
		<s:submit name="sub" key="my.submit" />
		<s:submit name="sub" key="my.register" />

	</s:form>
</body>
</html>


Action:

package com.hlx.action;

import com.opensymphony.xwork2.ActionSupport;

public class ChinaAction extends ActionSupport {
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return SUCCESS;
	}
}


struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<!-- 国际化配置 -->
	<constant name="struts.custom.i18n.resources" value="message" />
	<package name="hlx" namespace="/" extends="struts-default">
		<action name="china" class="com.hlx.action.ChinaAction">
			<result>/index.jsp</result>
		</action>
	</package>
</struts>    


语言配置文件:

message_en_US.properties:

my.title=English Page
my.name=username
my.pass=userpass
my.submit=submit
my.register=register


message_zh_CN.properties:

my.title=\u4E2D\u6587\u9875\u9762
my.name=\u7528\u6237\u540D
my.pass=\u5BC6\u7801
my.submit=\u63D0\u4EA4
my.register=\u6CE8\u518C

message_zh_TW.properties:

my.title=\u7E41\u9AD4\u9801\u9762
my.name=\u7528\u6236\u540D
my.pass=\u5BC6\u78BC
my.submit=\u63D0\u4EA4
my.register=\u8A3B\u518A





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值