- 浏览: 193069 次
- 性别:
文章分类
最新评论
-
sun5244725:
<if test="tenantIds.siz ...
Mybatis中传入List条件 -
springaop_springmvc:
可以参考最新的文档:如何在eclipse jee中检出项目并转 ...
Maven+Mybatis+Spring配置之第一步:配置pom.xml依赖 -
terryworld:
jiql 有很多SQL语法还不支持. 结果集内结果本身超过1 ...
jiql----Google APP Engine里的jdbc -
burnquist:
不知道jdoconfig.xml怎么写,直接复制官网的就报错
Google App Engine中使用JDO增强的问题 -
Aspen:
网上资料太少了,我也遇到类似的问题,郁闷中
Google App Engine中使用JDO增强的问题
1.创建项目
在eclipse里选择新建Maven Project,然后选择mave-archetype-webapp的Archetype,这样就会创建一个Eclipse WTP能识别的Web项目,能够Run on server。
2.修改POM
为项目加入相关的dependency,包括Spring,tiles等。
2.1添加Spring的依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
<scope>compile</scope>
</dependency>
这里只添加spring-webmvc的依赖,Maven会根据spring-webmvc包里的pom找到他需要的其他相关jar包的依赖,包括spring-core.jar,spring-bean.jar等。
2.2添加Tiles的依赖
在Apache Tiles的官方网站上的Download(http://tiles.apache.org/download.html)页面里有如何在Maven里加Tiles的依赖。
<!--[if !supportLists]-->· <!--[endif]--> The complete Tiles dependency with all supported technologies:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>2.2.2</version>
</dependency>
<!--[if !supportLists]-->· <!--[endif]-->The basic Tiles dependency with only servlet support:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>2.2.2</version>
</dependency>
<!--[if !supportLists]-->· <!--[endif]-->Tiles JSP support:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
2.3添加jstl依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
2.4添加Servlet相关的Provided依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
3.修改web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>tiles</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>tiles</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
这里servlet-name的值是tiles,并且没有给DispatcherServlet配置contextConfigLocation(可以通过这个值指定spring的配置文件),Spring MVC会从WEB-INF里去找tiles-servlet.xml的spring的配置文件。
4.tiles-servlet.xml
相关注视都在文档里
<?xml version="1.0" encoding="utf-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd "
default-autowire="byName"
default-lazy-init="false">
<!-- 当用户访问在webapp文件夹下的静态资源的时候,通过下面的配置直接访问,而不去找Controller -->
<mvc:resources
mapping="/resources/**"
location="/resources/" />
<!-- 为Spring MVC添加annotation-driven,该配置包括了对JSR-303 Validation,message conversion和filed
formatting -->
<mvc:annotation-driven />
<!-- 配置Spring扫描Controller存放的包路径 -->
<context:component-scan
base-package="com.rever.tiles.mvc" />
<!-- 配置Spring MVC的视图,从WEB-INF/views文件夹下去找对应的视图 -->
<!-- p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="1" -->
<bean
id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 为了使用JSTL Tag修改默认的viewClass属性 -->
<property
name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property
name="prefix"
value="/WEB-INF/views/" />
<property
name="suffix"
value=".jsp"></property>
<property
name="order"
value="1"></property>
</bean>
<!-- Convenience subclass of UrlBasedViewResolver that supports TilesView
(i.e. Tiles definitions) and custom subclasses of it. -->
<!-- Don't forget to set the order if you declared other ViewResolvers -->
<!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/view/tiles2/TilesViewResolver.html -->
<bean
id="tilesviewResolver"
class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<property
name="order"
value="0"></property>
</bean>
<!-- Helper class to configure Tiles 2.x for the Spring Framework -->
<!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/view/tiles2/TilesConfigurer.html -->
<!-- The actual tiles templates are in the tiles-definitions.xml -->
<bean
id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property
name="definitions">
<list>
<value>/WEB-INF/tiles-definitions.xml</value>
</list>
</property>
</bean>
</beans>
5. tiles-definitions.xml
<?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>
<!-- We declare a new template named template-main. This template is used
for displaying the main page. It has 4 attributes. These attributes are placeholder
for our contents For each attribute, we have assigned a corresponding JSP -->
<definition
name="template-main"
template="/WEB-INF/views/layouts/main.jsp">
<put-attribute
name="banner-content"
value="/WEB-INF/views/sections/banner.jsp" />
<put-attribute
name="title-content"
value="Pet Type" />
<put-attribute
name="primary-content"
value="" />
<put-attribute
name="footer-content"
value="/WEB-INF/views/sections/footer.jsp" />
</definition>
<!-- We declare a new template named template-detail. This template is used
for displaying details of an item. It has 5 attributes. These attributes
are placeholder for our contents For each attribute, we have assigned a corresponding
JSP -->
<definition
name="template-detail"
template="/WEB-INF/views/layouts/details.jsp">
<put-attribute
name="banner-content"
value="/WEB-INF/views/sections/banner.jsp" />
<put-attribute
name="title-content"
value="Pet Type" />
<put-attribute
name="subtitle-content"
value="" />
<put-attribute
name="primary-content"
value="" />
<put-attribute
name="footer-content"
value="/WEB-INF/views/sections/footer.jsp" />
</definition>
<!-- Concrete page. To use this page, your controller must return the name
"pet-tiles" -->
<definition
name="pet-tiles"
extends="template-main">
<put-attribute
name="primary-content"
value="/WEB-INF/views/contents/pets.jsp" />
</definition>
<!-- Concrete page. To use this page, your controller must return the name
"dog-tiles" -->
<definition
name="dog-tiles"
extends="template-detail">
<put-attribute
name="subtitle-content"
value="Canines" />
<put-attribute
name="primary-content"
value="/WEB-INF/views/contents/dogs.jsp" />
</definition>
<!-- Concrete page. To use this page, your controller must return the name
"cat-tiles" -->
<definition
name="cat-tiles"
extends="template-detail">
<put-attribute
name="subtitle-content"
value="Felines" />
<put-attribute
name="primary-content"
value="/WEB-INF/views/contents/cats.jsp" />
</definition>
</tiles-definitions>
在tiles的配置文件里定义了两个模板(template-main和template-detail),template-main模板的模板jsp文件是layouts/main.jsp,其内容如下:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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">
<style type="text/css">
body {
background: #555;
width: 400px;
border: 1px solid #fff;
padding: 0px;
}
div {
padding: 5px;
margin: 0px;
}
h1,h2,p {
padding: 0px;
margin: 0px;
}
#banner-style {
background: #3B3E37;
}
#title-style {
background: #665845;
}
#subtitle-style {
background: #9F8158;
}
#primary-style {
background: #EBC785;
}
#footer-style {
background: #733027;
}
</style>
<title>Insert title here</title>
</head>
<body style="background: #555;">
<div id="banner-style">
<tiles:insertAttribute name="banner-content" />
</div>
<div id="title-style">
<h2>
<tiles:insertAttribute name="title-content" />
</h2>
</div>
<div id="primary-style">
<tiles:insertAttribute name="primary-content" />
</div>
<div id="footer-style">
<tiles:insertAttribute name="footer-content" />
</div>
</body>
</html>
这里定义了banner-content,title-content,primary-content和footer-content几个大块内容,这些和tiles配置文件里的template-main模板里的元素对应。
<put-attribute
name="banner-content"
value="/WEB-INF/views/sections/banner.jsp" />
<put-attribute
name="title-content"
value="Pet Type" />
<put-attribute
name="primary-content"
value="" />
<put-attribute
name="footer-content"
value="/WEB-INF/views/sections/footer.jsp" />
从上面的代码中可以看出main.jsp中的banner-content使用sections/banner.jsp文件(应该是使用include)。title-content在这里就写死了,是Pet Type,当然子模板也可以覆盖这个属性。Primary-content这里没有设置内容,需要子模板提供相应的数据。Footer-content使用sections/footer.jsp文件。
子模板pet-tiles就继承了上面template-main模板,其内容如下:
<definition
name="pet-tiles"
extends="template-main">
<put-attribute
name="primary-content"
value="/WEB-INF/views/contents/pets.jsp" />
</definition>
可以看出,子模板中没有指定banner-content,title-content和footer-content,只是指定了primary-content,使用contents/pets.jsp文件。
6.Controller
Controller里没有什么好说的,唯一需要说明的是,在controller的方法里返回的视图名不是真正对应的jsp名,要对应tiles配置文件里的名字。比如上面的pet-tiles,而不能返回pets。
Tiles+Spring MVC相关的内容从http://krams915.blogspot.com/2010/12/spring-mvc-3-tiles-2-integration.html里看的,可以去这里查找原文章。
- tiles.zip (66.4 KB)
- 下载次数: 184
发表评论
-
Maven+Mybatis+Spring配置之第三步:生成Mybatis Bean
2011-05-31 20:23 58401.配置pom.xml 给pom.xml加Mybatis的pl ... -
Maven+Mybatis+Spring配置之第二步:配置Spring
2011-05-31 20:13 54971.配置Datasource: <bean id=& ... -
Maven+Mybatis+Spring配置之第一步:配置pom.xml依赖
2011-05-31 20:04 408671.配置slfj+logback: <!-- Log ... -
Spring的Annotation
2010-12-26 21:26 1093Spring支持的JSR-250和JSR-330 (Depen ... -
Spring容器的扩展点
2010-12-26 20:54 1530摘录自Spring文档的3.8节。 1.BeanPostPr ... -
Spring中多个lifecycle定义一个bean时的调用顺序
2010-12-26 18:00 1269初始化方法的调用顺序: 1.@PostConstruct修饰的 ... -
Spring3.0中对property设值的简化
2010-12-21 20:44 12501.p-namespace 在Spring3.0中,使用p-n ... -
执行mvn hibernate3:hbm2ddl
2010-04-15 13:37 3789在学习Maven的时候,看到http://www.sonaty ... -
在防火墙之后使用Maven访问Repository
2010-04-12 15:14 1962因为公司里需要代理才能上网,不能直接上远程的Repositor ...
相关推荐
Spring mvc tiles thinAdmin bootstrap Spring mvc tiles thinAdmin bootstrap Spring mvc tiles thinAdmin bootstrap
NULL 博文链接:https://haiker.iteye.com/blog/969715
NULL 博文链接:https://lshoo.iteye.com/blog/974781
NULL 博文链接:https://islove1945.iteye.com/blog/565197
通过策略接口,Spring 框架是高度可配置的,而且包含多种视图技术,例如 JavaServer Pages(JSP)技术、Velocity、Tiles、iText 和POI。Spring MVC 框架并不知道使用的视图,所以不会强迫您只使用 JSP 技术。Spring ...
spring-webmvc-tiles2.rar源码,可以直接导入Eclipse中!
主要给大家介绍了关于Spring mvc整合tiles框架的简单入门教程(maven),文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友可以参考借鉴,下面来一起看看详细的介绍吧。
这个jar文件包含Spring MVC框架相关的所有类。 包含国际化、标签、Theme、视图展现的FreeMarker、JasperReports、Tiles、Velocity、XSLT相关类。 当然,如果你的应用使用了独立的MVC框架,则无需这个JAR文件里的...
通过策略接口,Spring 框架是高度可配置的,而且包含多种视图技术,例如 JavaServer Pages(JSP)技术、Velocity、Tiles、iText 和POI。Spring MVC 框架并不知道使用的视图,所以不会强迫您只使用 JSP 技术。Spring ...
Thymeleaf (Done)Layout:Tiles3 integrate freemarker[原来打算使用thymeleaf集成tiles3的,不过目前thymeleaf只支持tiles2,后面会支持tiles3] (TODO)##故事(场景)以完成一个微型的电商系统为初期目标会员管理产品...
通过策略接口,Spring 框架是高度可配置的,而且包含多种视图技术,例如 JavaServer Pages(JSP)技术、Velocity、Tiles、iText 和POI。Spring MVC 框架并不知道使用的视图,所以不会强迫您只使用 JSP 技术。Spring ...
NULL 博文链接:https://clongjava.iteye.com/blog/1350754
spring3.0 MVC中文教程 翻译viralpatel.net网站文章,从Hello到MVC、国际化、Tiles框架集成、主题皮肤使用、hibernate集成使用、 在Spring3 MVC和Hibernate保存/ Retreving BLOB对象等教程使用,希望多大家有帮助。...
弹簧示例 使用 Spring JPA 和 Spring Security 进行身份验证的示例
Spring MVC 做个一个例子, 其中用的Dispatcher, tiles
通过策略接口,Spring 框架是高度可配置的,而且包含多种视图技术,例如 JavaServer Pages(JSP)技术、Velocity、Tiles、iText 和 POI。Spring MVC 框架并不知道使用的视图,所以不会强迫您只使用 JSP 技术。Spring...
该项目旨在介绍如何创建Spring MVC + Bootstrap + Tiles应用程序 图书馆 SpringMVC Apache Tiles 3.0.5 Bootstrap 3.2.0 jQuery 1.11.0 Log4j 要求 版本8+ 如何运行应用程序 在Windows上 # # Build application...