Results 1 to 6 of 6

Thread: Problem setting up Spring

  1. #1
    Join Date
    Nov 2011
    Posts
    11

    Default Problem setting up Spring

    I'm trying to move all my jsps into a folder under /WebContents/view but I keep getting a 404. Going to http://localhost:8080/test-app/ doesn't find my index.jsp under the view folder, but is ok in the WebContent folder. Why might this be? At the moment, I have to use http://localhost:8080/test-app/view/index.jsp to get to index page...

    I'm using Eclipse with Tomcat v7 integration.

    Also, should I need a controller? I wrote it because i had the view folder under WEB-INF previously but apparently folders under WEB-INF are protected, but can be accessed by code, but I didn't manage.

    dispatcher-servlet.xml

    Code:
    <?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:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <context:annotation-config />
        <context:component-scan base-package="controller" />
    
        <mvc:annotation-driven />
    
        <mvc:interceptors>
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
        </mvc:interceptors>
    
        <mvc:view-controller path="/" view-name="index" />
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/view/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
    </beans>
    web.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    
        <welcome-file-list>
            <welcome-file>dispatcher</welcome-file>
        </welcome-file-list>
        
        <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>/test-app/*</url-pattern>
        </servlet-mapping>
        
        <filter>
            <filter-name>urlRewriteFilter</filter-name>
            <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>urlRewriteFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
        
        <filter>
            <filter-name>sitemesh</filter-name>
            <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>sitemesh</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>REQUEST</dispatcher>
        </filter-mapping>
        
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
    </web-app>
    IndexController

    Code:
    package controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    public class IndexController {
    
        @RequestMapping(value = "/", method = RequestMethod.GET)
        public final String index() {
            return "index";
        }
    
    }
    Last edited by mt1; Nov 1st, 2011 at 04:11 PM.

  2. #2
    Join Date
    Nov 2011
    Posts
    12

    Default

    First thing first:
    When you go to http://localhost:8080/ do you get 404 error?

  3. #3
    Join Date
    Nov 2011
    Posts
    11

    Default

    Quote Originally Posted by Elad View Post
    First thing first:
    When you go to http://localhost:8080/ do you get 404 error?
    I get the Tomcat management page.

    Edit:
    localhost_access_log.2011-11-01.txt

    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:09:31 +0000] "GET /test-app/ HTTP/1.1" 404 982
    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:09:50 +0000] "GET /test-app/ HTTP/1.1" 404 982
    127.0.0.1 - - [01/Nov/2011:21:10:00 +0000] "GET / HTTP/1.1" 200 12079
    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:10:08 +0000] "GET /test-app/ HTTP/1.1" 404 982
    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:10:44 +0000] "GET /test-app/ HTTP/1.1" 404 982

  4. #4
    Join Date
    Nov 2011
    Posts
    12

    Default

    Quote Originally Posted by mt1 View Post
    I get the Tomcat management page.

    Edit:
    localhost_access_log.2011-11-01.txt

    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:09:31 +0000] "GET /test-app/ HTTP/1.1" 404 982
    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:09:50 +0000] "GET /test-app/ HTTP/1.1" 404 982
    127.0.0.1 - - [01/Nov/2011:21:10:00 +0000] "GET / HTTP/1.1" 200 12079
    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:10:08 +0000] "GET /test-app/ HTTP/1.1" 404 982
    0:0:0:0:0:0:0:1 - - [01/Nov/2011:21:10:44 +0000] "GET /test-app/ HTTP/1.1" 404 982
    Cool.
    I'm guessing the Web-Content folder was created when you created the project from eclipse wizard.
    Is that correct?
    In most Spring examples I saw, it's actually the same as WEB-INF folder.
    Try to put all the content you have in Web-Content in WEB-INF.
    Do you still get an error?

  5. #5
    Join Date
    Nov 2011
    Posts
    11

    Default

    Quote Originally Posted by Elad View Post
    Cool.
    I'm guessing the Web-Content folder was created when you created the project from eclipse wizard.
    Is that correct?
    In most Spring examples I saw, it's actually the same as WEB-INF folder.
    Try to put all the content you have in Web-Content in WEB-INF.
    Do you still get an error?
    Yeah the WebContent folder was created by default.

    Still get same error...

  6. #6
    Join Date
    Nov 2011
    Posts
    11

    Default

    It seems to not work with projects like from this tutorial either...

    http://viralpatel.net/blogs/2010/06/...ing-3-mvc.html

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •