Announcement Announcement Module
No announcement yet.
Controller-backed index page Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller-backed index page

    I would like to have my main index page backed by a controller so I can fill the "welcome" page with data from my Entities. I created a controller as such:
    web mvc controller --class ~.web.SiteController
    Then I modified the RequestMapping of that controller to:
    The full class now looks like this:
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    public class SiteController {
        public void get(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
        @RequestMapping(method = RequestMethod.POST, value = "{id}")
        public void post(@PathVariable Long id, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
        public String index() {
            return "site/index";
    However, when I hit my main URL, I get an error saying the resource was not found:
    Requested Resource Not Found

    Sorry, we did not find the resource you were looking for.


    Exception Message
    No matching handler method found for servlet request: path '/', method 'GET', parameters map[[empty]]
    Exception Stack Trace
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.resolveHandlerMethod(AnnotationMethodHandle
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho
    org.springframework.web.servlet.DispatcherServlet. doDispatch(
    org.springframework.web.servlet.DispatcherServlet. doService(
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(
    org.springframework.web.servlet.FrameworkServlet.d oGet(
    javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722) ternalDoFilter( Filter( gerInViewFilter.doFilterInternal(OpenEntityManager
    org.springframework.web.filter.OncePerRequestFilte r.doFilter( ternalDoFilter( Filter($ VirtualFilterChain.doFilter( 368) FilterSecurityInterceptor.invoke(FilterSecurityInt FilterSecurityInterceptor.doFilter(FilterSecurityI$ VirtualFilterChain.doFilter( 380) ranslationFilter.doFilter(ExceptionTranslationFilt$ VirtualFilterChain.doFilter( 380) nagementFilter.doFilter(SessionManagementFilter.ja va:100)$ VirtualFilterChain.doFilter( 380) onymousAuthenticationFilter.doFilter(AnonymousAuth$ VirtualFilterChain.doFilter( 380) tyContextHolderAwareRequestFilter.doFilter(Securit$ VirtualFilterChain.doFilter( 380) estCacheAwareFilter.doFilter(RequestCacheAwareFilt$ VirtualFilterChain.doFilter( 380)$ VirtualFilterChain.doFilter( 380) stractAuthenticationProcessingFilter.doFilter(Abst$ VirtualFilterChain.doFilter( 380) gout.LogoutFilter.doFilter($ VirtualFilterChain.doFilter( 380) ontextPersistenceFilter.doFilter(SecurityContextPe$ VirtualFilterChain.doFilter( 380) doFilter(
    org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(
    org.springframework.web.filter.DelegatingFilterPro xy.doFilter( ternalDoFilter( Filter(
    org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal( 7)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter( ternalDoFilter( Filter(
    org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal( :88)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter( ternalDoFilter( Filter(
    org.apache.catalina.core.StandardWrapperValve.invo ke(
    org.apache.catalina.core.StandardContextValve.invo ke(
    org.apache.catalina.authenticator.AuthenticatorBas e.invoke(
    org.apache.catalina.valves.ErrorReportValve.invoke (
    org.apache.catalina.core.StandardEngineValve.invok e(
    com.springsource.insight.collection.tcserver.reque st.HttpRequestOperationCollectionValve.traceNextVa lve(
    com.springsource.insight.collection.tcserver.reque st.HttpRequestOperationCollectionValve.invoke(Http
    org.apache.catalina.connector.CoyoteAdapter.servic e(
    org.apache.coyote.AbstractProtocol$AbstractConnect ionHandler.process($SocketProce
    java.util.concurrent.ThreadPoolExecutor$ Task(
    java.util.concurrent.ThreadPoolExecutor$ (
    Can someone with more knowledge point me in the right place?

  • #2
    You simply cannot. It is a limitation from the servlet spec, the welcome file has to be an actual file existing on the file system. You can work around it by creating an index.jsp (or whatever you want) which simply redirects to your site controller.


    • #3
      Well, that sucks . Guess I will have to use JSPs or something then.


      • #4
        mbabauer, You're on the right path. I created a controller and commented out the static view root path:
        <!-- <mvc:view-controller path="/" view-name="index"/> -->
        in the webmvc-config.xml file.
        I added
        @RooWebScaffold(path = "", formBackingObject = [ClassName].class)
        to my controller as I had a form on my index page, index.jspx.
        When you use the @RooWebScaffold annotation Roo will create controller methods in an .aj file which you can use after you push-in the generated methods in order to modify them and expose and work with your entity, if needed.


        1. Remove the static view root path from webmvc-config.xml.
        2. Add @RooWebScaffold(path = "" ..... to your Controller.
        3. Check the return strings in the "...Controller_Roo_Controller.aj file. If they are faulty push them in and correct them in java source.
        4. Edit the managed views.xml file and remove the extra slashes, if any, from the generated paths of the put-attribute element.

        There could still be some problems you'd need to address, but generally that would work I think.
        It may also help to make the whole concept the regular way in another path first and consult that as a reference.

        I made a Roo bug report on this matter last march: "Controller scaffold command which works for the rootpath". Please vote for it if you feel this would be a welcome feature.
        Last edited by MiB; Dec 27th, 2011, 01:15 AM. Reason: Corrected


        • #5
          Ah, so it IS possible. Thanks so much for the info on how to do it.

          Also, I voted for your JIRA story.


          • #6
            I added some steps above.