Skip to content

Commit 657d1a5

Browse files
authored
Add files via upload
1 parent 11241ea commit 657d1a5

13 files changed

Lines changed: 339 additions & 0 deletions

File tree

‎spring-mvc-tiles/pom.xml‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.baeldung</groupId>
4+
<artifactId>spring-mvc-tiles</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>war</packaging>
7+
<name>spring-mvc-tiles</name>
8+
<description>Integrating Spring MVC with Apache Tiles</description>
9+
10+
<properties>
11+
<springframework.version>4.3.2.RELEASE</springframework.version>
12+
<apachetiles.version>3.0.5</apachetiles.version>
13+
</properties>
14+
15+
<dependencies>
16+
<!-- Spring -->
17+
<dependency>
18+
<groupId>org.springframework</groupId>
19+
<artifactId>spring-core</artifactId>
20+
<version>${springframework.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework</groupId>
24+
<artifactId>spring-web</artifactId>
25+
<version>${springframework.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework</groupId>
29+
<artifactId>spring-webmvc</artifactId>
30+
<version>${springframework.version}</version>
31+
</dependency>
32+
<!-- Apache Tiles -->
33+
<dependency>
34+
<groupId>org.apache.tiles</groupId>
35+
<artifactId>tiles-core</artifactId>
36+
<version>${apachetiles.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.apache.tiles</groupId>
40+
<artifactId>tiles-api</artifactId>
41+
<version>${apachetiles.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.apache.tiles</groupId>
45+
<artifactId>tiles-servlet</artifactId>
46+
<version>${apachetiles.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.apache.tiles</groupId>
50+
<artifactId>tiles-jsp</artifactId>
51+
<version>${apachetiles.version}</version>
52+
</dependency>
53+
54+
<!-- Servlet+JSP+JSTL -->
55+
<dependency>
56+
<groupId>javax.servlet</groupId>
57+
<artifactId>javax.servlet-api</artifactId>
58+
<version>3.1.0</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>javax.servlet.jsp</groupId>
62+
<artifactId>javax.servlet.jsp-api</artifactId>
63+
<version>2.3.1</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>javax.servlet</groupId>
67+
<artifactId>jstl</artifactId>
68+
<version>1.2</version>
69+
</dependency>
70+
71+
</dependencies>
72+
73+
<build>
74+
<pluginManagement>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-compiler-plugin</artifactId>
79+
<version>3.2</version>
80+
<configuration>
81+
<source>1.7</source>
82+
<target>1.7</target>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-war-plugin</artifactId>
88+
<version>2.4</version>
89+
<configuration>
90+
<warSourceDirectory>src/main/webapp</warSourceDirectory>
91+
<warName>spring-mvc-tiles</warName>
92+
<failOnMissingWebXml>false</failOnMissingWebXml>
93+
</configuration>
94+
</plugin>
95+
</plugins>
96+
</pluginManagement>
97+
<finalName>spring-mvc-tiles</finalName>
98+
</build>
99+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.tiles.springmvc;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
7+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
8+
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
9+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
10+
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
11+
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
12+
13+
@Configuration
14+
@EnableWebMvc
15+
@ComponentScan(basePackages = "com.baeldung.tiles.springmvc")
16+
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
17+
18+
/**
19+
* Configure TilesConfigurer.
20+
*/
21+
@Bean
22+
public TilesConfigurer tilesConfigurer() {
23+
TilesConfigurer tilesConfigurer = new TilesConfigurer();
24+
tilesConfigurer.setDefinitions(new String[] { "/WEB-INF/views/**/tiles.xml" });
25+
tilesConfigurer.setCheckRefresh(true);
26+
return tilesConfigurer;
27+
}
28+
29+
/**
30+
* Configure ViewResolvers to deliver views.
31+
*/
32+
@Override
33+
public void configureViewResolvers(ViewResolverRegistry registry) {
34+
TilesViewResolver viewResolver = new TilesViewResolver();
35+
registry.viewResolver(viewResolver);
36+
}
37+
38+
/**
39+
* Configure ResourceHandlers to serve static resources
40+
*/
41+
42+
@Override
43+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
44+
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
45+
}
46+
47+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.tiles.springmvc;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.ui.ModelMap;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
8+
9+
@Controller
10+
@RequestMapping("/")
11+
public class ApplicationController {
12+
13+
@RequestMapping(value = { "/"}, method = RequestMethod.GET)
14+
public String homePage(ModelMap model) {
15+
return "home";
16+
}
17+
18+
@RequestMapping(value = { "/apachetiles"}, method = RequestMethod.GET)
19+
public String productsPage(ModelMap model) {
20+
return "apachetiles";
21+
}
22+
23+
@RequestMapping(value = { "/springmvc"}, method = RequestMethod.GET)
24+
public String contactUsPage(ModelMap model) {
25+
return "springmvc";
26+
}
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.tiles.springmvc;
2+
3+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4+
5+
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
6+
7+
@Override
8+
protected Class<?>[] getRootConfigClasses() {
9+
return new Class[] { ApplicationConfiguration.class };
10+
}
11+
12+
@Override
13+
protected Class<?>[] getServletConfigClasses() {
14+
return null;
15+
}
16+
17+
@Override
18+
protected String[] getServletMappings() {
19+
return new String[] { "/" };
20+
}
21+
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<title>Apache Tiles</title>
8+
</head>
9+
<body>
10+
<h2>Tiles with Spring MVC Demo</h2>
11+
</body>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<title>Home</title>
8+
</head>
9+
<body>
10+
<h2>Welcome to Apache Tiles integration with Spring MVC</h2>
11+
</body>
12+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<title>Spring MVC</title>
8+
</head>
9+
<body>
10+
<h2>Spring MVC configured to work with Apache Tiles</h2>
11+
</body>
12+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2+
pageEncoding="ISO-8859-1"%>
3+
<%@ page isELIgnored="false"%>
4+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
5+
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
6+
7+
<html>
8+
9+
<head>
10+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
11+
<title><tiles:getAsString name="title" /></title>
12+
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
13+
</head>
14+
15+
<body>
16+
<div class="flex-container">
17+
<tiles:insertAttribute name="header" />
18+
<tiles:insertAttribute name="menu" />
19+
<article class="article">
20+
<tiles:insertAttribute name="body" />
21+
</article>
22+
<tiles:insertAttribute name="footer" />
23+
</div>
24+
</body>
25+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
<footer>copyright © Baeldung</footer>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<header>
2+
<h1>Welcome to Spring MVC integration with Apache Tiles</h1>
3+
</header>

0 commit comments

Comments
 (0)