java - apache tiles integration with spring mvc -
i new tiles concept.i tried use apache tiles spring. used urlbasedviewresolver render view.the problem it, rendering view multiple times in single page.where mistake ?
it sholud display once displays contineously,till server throws exception.below stacktrace
info: mapped "{[/hello],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.modelandview com.controller.testcontroller.helloworld() nov 27, 2014 3:04:08 pm org.springframework.web.servlet.view.tiles2.tilesconfigurer setdefinitions info: tilesconfigurer: adding definitions [/web-inf/tiles.xml] .15:04:09.408 [http-nio-8080-exec-1] info o.a.t.c.abstracttilesapplicationcontextfactory - initializing tiles2 application context. . . .15:04:09.424 [http-nio-8080-exec-1] info o.a.t.c.abstracttilesapplicationcontextfactory - finished initializing tiles2 application context. .15:04:09.565 [http-nio-8080-exec-1] info org.apache.tiles.access.tilesaccess - publishing tilescontext context: org.springframework.web.servlet.view.tiles2.springtilesapplicationcontextfactory$springwildcardservlettilesapplicationcontext nov 27, 2014 3:04:09 pm org.springframework.web.servlet.dispatcherservlet initservletbean info: frameworkservlet 'mvc': initialization completed in 2625 ms hello world, spring 3.0! nov 27, 2014 3:04:09 pm org.apache.catalina.core.applicationdispatcher invoke severe: servlet.service() servlet jsp threw exception java.lang.stackoverflowerror @ javax.servlet.servletresponsewrapper.iscommitted(servletresponsewrapper.java:183) @ javax.servlet.servletresponsewrapper.iscommitted(servletresponsewrapper.java:183) @ javax.servlet.servletresponsewrapper.iscommitted(servletresponsewrapper.java:183) @ org.apache.jsp.web_002dinf.jsp.layout_jsp._jspservice(layout_jsp.java:119) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:725) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:396) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:340) @ javax.servlet.http.httpservlet.service(httpservlet.java:725) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:721) @ org.apache.catalina.core.applicationdispatcher.doinclude(applicationdispatcher.java:584) @ org.apache.catalina.core.applicationdispatcher.include(applicationdispatcher.java:523) @ org.apache.jasper.runtime.jspruntimelibrary.include(jspruntimelibrary.java:934) @ org.apache.jasper.runtime.pagecontextimpl.doinclude(pagecontextimpl.java:676) @ org.apache.jasper.runtime.pagecontextimpl.include(pagecontextimpl.java:670) @ org.apache.tiles.jsp.context.jsptilesrequestcontext.include(jsptilesrequestcontext.java:103) @ org.apache.tiles.jsp.context.jsptilesrequestcontext.dispatch(jsptilesrequestcontext.java:96) @ org.apache.tiles.renderer.impl.templateattributerenderer.write(templateattributerenderer.java:44) @ org.apache.tiles.renderer.impl.abstractbaseattributerenderer.render(abstractbaseattributerenderer.java:106) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:670) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:690) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:644) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:627) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:321) @ org.apache.tiles.renderer.impl.definitionattributerenderer.write(definitionattributerenderer.java:56) @ org.apache.tiles.renderer.impl.abstractbaseattributerenderer.render(abstractbaseattributerenderer.java:106) @ org.apache.tiles.renderer.impl.chaineddelegateattributerenderer.write(chaineddelegateattributerenderer.java:76) @ org.apache.tiles.renderer.impl.abstractbaseattributerenderer.render(abstractbaseattributerenderer.java:106) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:670) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:336) @ org.apache.tiles.template.insertattributemodel.renderattribute(insertattributemodel.java:210) @ org.apache.tiles.template.insertattributemodel.end(insertattributemodel.java:126) @ org.apache.tiles.jsp.taglib.insertattributetag.dotag(insertattributetag.java:311) @ org.apache.jsp.web_002dinf.jsp.layout_jsp._jspx_meth_tiles_005finsertattribute_005f0(layout_jsp.java:145) @ org.apache.jsp.web_002dinf.jsp.layout_jsp._jspservice(layout_jsp.java:81) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:725) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:396) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:340) @ javax.servlet.http.httpservlet.service(httpservlet.java:725) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:721) @ org.apache.catalina.core.applicationdispatcher.doinclude(applicationdispatcher.java:584) @ org.apache.catalina.core.applicationdispatcher.include(applicationdispatcher.java:523) @ org.apache.jasper.runtime.jspruntimelibrary.include(jspruntimelibrary.java:934) @ org.apache.jasper.runtime.pagecontextimpl.doinclude(pagecontextimpl.java:676) @ org.apache.jasper.runtime.pagecontextimpl.include(pagecontextimpl.java:670) @ org.apache.tiles.jsp.context.jsptilesrequestcontext.include(jsptilesrequestcontext.java:103) @ org.apache.tiles.jsp.context.jsptilesrequestcontext.dispatch(jsptilesrequestcontext.java:96) @ org.apache.tiles.renderer.impl.templateattributerenderer.write(templateattributerenderer.java:44) @ org.apache.tiles.renderer.impl.abstractbaseattributerenderer.render(abstractbaseattributerenderer.java:106) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:670) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:690) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:644) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:627) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:321) @ org.apache.tiles.renderer.impl.definitionattributerenderer.write(definitionattributerenderer.java:56) @ org.apache.tiles.renderer.impl.abstractbaseattributerenderer.render(abstractbaseattributerenderer.java:106) @ org.apache.tiles.renderer.impl.chaineddelegateattributerenderer.write(chaineddelegateattributerenderer.java:76) @ org.apache.tiles.renderer.impl.abstractbaseattributerenderer.render(abstractbaseattributerenderer.java:106) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:670) @ org.apache.tiles.impl.basictilescontainer.render(basictilescontainer.java:336) @ org.apache.tiles.template.insertattributemodel.renderattribute(insertattributemodel.java:210) @ org.apache.tiles.template.insertattributemodel.end(insertattributemodel.java:126) @ org.apache.tiles.jsp.taglib.insertattributetag.dotag(insertattributetag.java:311)
below code
testcontroller.java
@controller public class testcontroller { @requestmapping("/hello") public modelandview helloworld() { string message = "hello world, spring 3.0!"; system.out.println(message); return new modelandview("hello", "message", message); } }
app-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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="com"/> <bean id="viewresolver" class="org.springframework.web.servlet.view.urlbasedviewresolver"> <property name="viewclass"> <value> org.springframework.web.servlet.view.tiles2.tilesview </value> </property> </bean> <bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles2.tilesconfigurer"> <property name="definitions"> <list> <value>/web-inf/tiles.xml</value> </list> </property> </bean> </beans>
tiles.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> <definition name="base.definition" template="/web-inf/jsp/layout.jsp"> <put-attribute name="title" value="" /> <put-attribute name="header" value="/web-inf/jsp/header.jsp" /> <put-attribute name="menu" value="/web-inf/jsp/menu.jsp" /> <put-attribute name="body" value="" /> <put-attribute name="footer" value="/web-inf/jsp/footer.jsp" /> </definition> <definition name="hello" extends="base.definition"> <put-attribute name="title" value="hello" /> <put-attribute name="body" value="/web-inf/jsp/hello.jsp" /> </definition> </tiles-definitions>
layout.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" 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><tiles:insertattribute name="title" ignore="true" /></title> </head> <body> <table border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <td height="30" colspan="2"><tiles:insertattribute name="header" /> </td> </tr> <tr> <td height="250"><tiles:insertattribute name="menu" /></td> <td width="350"><tiles:insertattribute name="body" /></td> </tr> <tr> <td height="30" colspan="2"><tiles:insertattribute name="footer" /> </td> </tr> </table> </body> </html>
hello.jsp
<%@ page iselignored="false" %> <html> <head> <title>spring 3.0 mvc series: hello world</title> </head> <body> ${message} </body> </html>
mistake in tiles.xml,here is
<definition name="hello" extends="base.definition"> <put-attribute name="title" value="hello" /> <put-attribute name="body" value="/web-inf/jsp/hello.jsp" /> </definition>
i should not write <put-attribute name="title" value="hello" />
,because in hello.jsp title added.so definition should this
<definition name="hello" extends="base.definition"> <put-attribute name="body" value="/web-inf/jsp/hello.jsp" /> </definition>
Comments
Post a Comment