0
votes

I'm having a problem trying to get it up . In index.jsp ( where the app starts) I have ...

<jsp:forward page="hello.do"></jsp:forward>

Then, in web.xml I have defined the servlet dispatcher :

<!-- Servlet para levantar el dispatcher servlet de spring MVC -->
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

So, everything that ends with .do, should be taken by the controller . That works . The controller defined is :

@Controller
@RequestMapping("/hello")
public class HelloWorldController {
    @RequestMapping(method=RequestMethod.GET)
    public String procesar(HttpServletRequest request,ModelMap modelo){
        System.out.println("todo jodidamente correcto");
        String mensaje = "Hola, perras";

        modelo.addAttribute("message",mensaje);

        return "hello";
    }
}

I can see the message, but it fails when it gets to -- return "hello" -- , that I still have the same exception :

javax.servlet.ServletException: Could not resolve view with name 'hello' in servlet with name 'dispatcher'
org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1013)
org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:815)
org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:717)
org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)

my tile definition is :

<tiles-definitions>
    <definition name="topfisio.layout" template="/layouts/three-layer.jsp">
        <put-attribute name="title" value="Top fisio" />
        <put-attribute name="header" value="/jsp/header.jsp" />
        <put-attribute name="footer" value="/jsp/footer.jsp" />
    </definition>


    <definition name="*" extends="topfisio.layout">
        <put-attribute name="title" value="{1}" />
        <put-attribute name="content" value="/jsp/{1}.jsp"/>
    </definition>
</tiles-definitions>

and my file structure is :

index.jsp

WEB-INF
WEB-INF -- dispatcher-servlet.xml
WEB-INF -- tiles-def.xml
WEB-INF -- web.xml
layouts
layouts -- three-layer.jsp
jsp
jsp -- footer.jsp
jsp -- header.jsp
jsp -- hello.jsp

I may have a problem with tiles definitions , but I still cant find it

1

1 Answers

1
votes

You have to configure in your dispatcher-servlet.xml the resolver for tiles, so when you return a string in the controller Spring will go over all your resolvers trying looking for the appropiate one:

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles-def.xml</value>
        </list>
    </property>
</bean>

<bean id="tilesResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
     <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
     <!-- In case you have more than one resolver you can set the order here -->
     <!-- The order 0 will be the first one in the order -->
     <property name="order" value="1"/>              

More info here