Struts2学习之旅二 tiles布局和权限管理
来源:互联网 发布:淘宝店代销如何找货源 编辑:程序博客网 时间:2024/06/05 05:39
转载:http://www.cnblogs.com/snidget/archive/2013/06/14/3136138.html
做了一个CRUD之后,算是迈出了最简单的第一步,现在我们要做一个高级一点的东西,tiles布局和权限管理,有信心和激情去完成它。
1,tiles是神马?用它可以干什么?为什么要使用它?
tiles是一种模版机制,将网页的内容和布局分离;
用它来减少重复的页面编码;
可灵活的跟JSF,Spring,Struts2框架整合到一起。
2,先看看我使用tiles做的一个后台管理系统的主页的效果,太丑陋了,见笑了;
创建的步骤,来个xmind;
下面列出要点:
步骤要点必要的依赖1,在web.xml中增加一个监听器,配置两个常量;<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener><context-param>
公共的页面代码简单点内容页面,比如head.jsp,bottom.jsp,leftBox.jsp,举个例子:
<param-name>org.apache.tiles.CONTAINER_FACTORY</param-name>
<param-value>org.apache.struts2.tiles.StrutsTilesContainerFactory</param-value>
</context-param>
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles/tiles.xml,
/WEB-INF/tiles/tiles-adminUser.xml
</param-value>
</context-param><%@ page language="java" contentType="text/html; charset=UTF-8"
模版代码
pageEncoding="UTF-8"%>
<div style="background-color:gray;text-align: center;">
Cutter哥哥后台管理系统
</div>主要是定义一种布局样式:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/tiles-jsp.tld" prefix="tiles"%>
<!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=UTF-8">
<title>基本模版</title>
<style type="text/css">
body {
text-decoration: none;
width: 100%;
height: 100%;
text-align: center;
}.head {
width: 100%;
height: 50px;
background-color: green;
}.bottom {
width: 100%;
height: 30px;
background-color: green;
}.leftBox {
width: 100px;
height: 600px;
background-color: green;
clear:both;
float: left;
}.content {
组件组件的模版,tiles支持继承;
width: 600px;
height: 600px;
clear: right;
}
</style>
</head>
<body>
<div class="head">
<tiles:insertAttribute name="head"/>
</div>
<div class="leftBox">
<tiles:insertAttribute name="leftBox"/>
</div>
<div class="content">
<tiles:insertAttribute name="content"/>
</div>
<div class="bottom">
<tiles:insertAttribute name="bottom"/>
</div>
</body>
</html><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<!--首页-->
<definition name="adminDefaultLayout" template="/WEB-INF/web/common/home.jsp">
<!-- <put-attribute name="titleKey" value="PageTitle" type="string"/>-->
<put-attribute name="head" value="/WEB-INF/web/common/head.jsp"/>
<put-attribute name="leftBox" value="/WEB-INF/web/common/leftBox.jsp"/>
<put-attribute name="content" value=""/>
<put-attribute name="bottom" value="/WEB-INF/web/common/bottom.jsp"/>
</definition>
</tiles-definitions>来一个实例组件:使用的时候分模块定义tiles组件;
<?xml version="1.0" encoding="UTF-8"?>
urlmap使用
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="adminUserList" extends="adminDefaultLayout">
<put-attribute name="content" value="/manager/index.jsp" />
</definition>
</tiles-definitions>直接贴一个xml的配置文件,要点标红了,如果没有 tiles-default,会报type为tiles的错误;tiles指向的是组件的名称,组件在应用启动的时候已经加载!
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="user" extends="struts-default,tiles-default" namespace="/account">
<action name="login" class="com.cutter.web.account.action.user.LoginOutAction" method="index" >
<result name="success">/manager/adminLogin.jsp</result>
</action>
<action name="loginSubmit" class="com.cutter.web.account.action.user.LoginOutAction" method="login">
<result name="success" type="tiles">adminUserList</result>
<result name="input">/manager/adminLogin.jsp</result>
</action>
</package>
</struts>
先搞基本的,下一个随笔次分析下tiles的执行过程和原理;大家多支持。
3,权限管理的基本思想:
- Struts2学习之旅二 tiles布局和权限管理
- Struts2和Tiles集成
- struts2的Tiles管理页面
- Linux学习笔记二之权限管理命令
- Tiles与siteMesh页面布局管理
- acegi权限管理之二
- Linux 权限管理之二:setuid、setgid 和 sticky bit
- Java布局管理器(二)之FlowLayout(流布局管理)和BorderLayout(边框布局管理)
- jbpm4.3+struts2+spring3+hibernate3整合(二)之权限管理
- linux 学习之权限管理
- QT学习之 布局管理
- Oracle学习笔记(二)---权限管理
- MySQL学习笔记二:权限管理
- 【Linux学习笔记】二、权限管理命令
- Qt学习笔记(二)布局管理
- Struts2学习之二--Struts2标签介绍
- 常见的权限管理设计之二
- struts系列学习(tiles标签库二)
- Fragment开发实战(二)
- 干货分享:主流的App推广形式和费用详解
- 【Spark亚太研究院系列丛书】Spark实战高手之路-第一章 构建Spark集群(第四步)(4)
- 64位 windows JDK JRE 下使用xmind
- struts-config.xml配置文件详解
- Struts2学习之旅二 tiles布局和权限管理
- hdu 5023 A Corrupt Mayor's Performance Art(线段树)
- ArcGIS教程:创建经验半变异函数
- Java实现BASE64编解码
- android打印调用堆栈
- 工作报告0922
- 正则表达式工具
- unsigned 既为非负数
- Sort Colors [leetcode] 扫描数组一遍,O(1)空间复杂度的解法