mardi 3 mars 2015

How to handle addressing to static pages in Spring MVC + Tiles3

I have a Spring MVC application that is using Tile3. I have many static pages that need to have them in the template of the website. (Provided by tile). How can I access these static pages? should I do it through a controller? Examples of static pages are index.jsp and aboutus.jsp. I need to have the same footer and header on all pages, either dynamic or static but not sure how to do the addressing.


web.xml



<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" xmlns="http://ift.tt/qzwahU"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/qzwahU
http://ift.tt/16hRdKA">


<listener>
<listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springapp-servlet.xml</param-value>
</context-param>



</web-app>


tiles.xml



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://ift.tt/VbUdcJ">

<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/templates/baseLayout.jsp">
<put-attribute name="title" value="Title is here (Tile)"/>
<put-attribute name="header" value="Title is here (Tile)"/>
<put-attribute name="menu" value="Title is here (Tile)"/>
<put-attribute name="body" value="Title is here (Tile)"/>
<put-attribute name="footer" value="Title is here (Tile)"/>

</definition>

<definition name="hello" extends="baseLayout">
<put-attribute name="title" value="HELERE"/>
<put-attribute name="body" value="/WEB-INF/pages/pages/ewfsdfsdf.jsp"/>
</definition>

<definition name="index" extends="baseLayout">
<put-attribute name="title" value="HELERE"/>
<put-attribute name="body" value="/WEB-INF/pages/index.jsp"/>
</definition>
</tiles-definitions>


Controller



@Controller
public class HelloController {

protected final Log logger = LogFactory.getLog(getClass());

public HelloController() {
System.err.println("Constructor of HelloController");
}

@RequestMapping("/index.htm")
public String index(){
System.err.println("in index method");
return "index";
}

Aucun commentaire:

Enregistrer un commentaire