Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Spring Mvc 404 error

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Spring Mvc 404 error

    Hi:

    I took a course on Spring 2.56 from Interface21 and the labs I got get it to work during the training.

    But when I tried it at home it doesn't work.
    I go to the following url and it's find.
    http://localhost:8080/accounts/

    It display "This is my JSP page. " This is from the default index.jsp page.
    When I tried the url as suggested in the lab "http://localhost:8080/accounts/accountSummary.htm"

    It gives me a 404 error.

    Note, the Tomcat 6 console didnot show any errors meaning it didn't invoke the code for the url.
    I am using Myeclipse 8 on Tomcat6.
    Here is my Spring information:

    Web.xml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    Java 2 Platform, Enterprise Edition (J2EE) : XML Schemas for J2EE Deployment Descriptors
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <!-- Beans in these files will makeup the configuration of the root web application context -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/accounts-application-config.xml</param-value>
    </context-param>

    <!-- Bootstraps the root web application context before servlet initialization -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    <!-- Deploys the 'accounts' dispatcher servlet whose configuration resides in /WEB-INF/accounts-servlet-config.xml -->
    <servlet>
    <servlet-name>accounts</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/accounts-servlet-config.xml</param-value>
    </init-param>
    </servlet>

    <!-- Maps all /accounts URLs to the 'accounts' servlet -->
    <servlet-mapping>
    <servlet-name>accounts</servlet-name>
    <url-pattern>/accounts/*</url-pattern>
    </servlet-mapping>

    </web-app>

    Accounts-servlet-config.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.5.xsd
    Index of /schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!--
    The configuration for your 'accounts' Dispatcher Servlet.

    This example uses component scanning to automatically
    pick up controllers.
    - Dependencies of controllers are wired using @Autowired support.
    - The URI scheme is controller using @RequestMapping annotations
    -->

    <context:component-scan base-package="accounts.web"/>

    <!--
    if you would not have used component scanning you would have had
    to wire up the controller yourself:

    <bean class="accounts.web.AccountController">
    <constructor-arg ref="accountManager"/>
    </bean>
    -->

    <bean class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
    </bean>

    </beans>

    accounts-application-config.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:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.5.xsd
    Index of /schema/tx
    http://www.springframework.org/schem...ing-tx-2.5.xsd
    Index of /schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- The configuration of the account manager application. -->

    <context:annotation-config/>

    <!-- Weaves in transactional advice around @Transactional methods -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- The account manager service that can load accounts from the database -->
    <bean id="accountManager" class="accounts.internal.HibernateAccountManager">
    <constructor-arg ref="sessionFactory" />
    </bean>

    <!-- A Hibernate SessionFactory for mapping Accounts and Restaurants from object to relation tables -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingLocations">
    <list>
    <value>classpath:accounts/internal/Account.hbm.xml</value>
    <value>classpath:accounts/internal/Beneficiary.hbm.xml</value>
    </list>
    </property>
    </bean>

    <!-- Creates an in-memory "rewards" database populated with test data for fast testing -->
    <bean id="dataSource" class="accounts.testdb.TestDataSourceFactory">
    <property name="testDatabaseName" value="rewards"/>
    <property name="schemaLocation" value="classpath:accounts/testdb/schema.sql"/>
    <property name="testDataLocation" value="classpath:accounts/testdb/test-data.sql"/>
    </bean>

    <!-- Drives transactions using Hibernate APIs when requested -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <!-- Translates Hibernate exceptions to Spring Data Access Exceptions -->
    <bean class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor"/>

    </beans>
    Here is the AccountControler.java:
    package accounts.web;
     
    import java.util.List;
     
    import javax.servlet.http.HttpServletRequest;
     
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.ServletRequestBindingException;
    import org.springframework.web.bind.ServletRequestUtils;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
     
    import accounts.Account;
    import accounts.AccountManager;
     
    /**
     * A Spring MVC @Controller controller handling requests for both the
     * account summary and the account details pages. The accountDetails()
     * method return an account, corresponding to a given entity id. The
     * accountSummary() method returns a list with all accounts.  
     */
    @Controller
    public class AccountController {
     
        private AccountManager accountManager;
     
        /**
         * Creates a new AccountController with a given account manager.
         */
        @Autowired public AccountController(AccountManager accountManager) {
            this.accountManager = accountManager;
        }
     
     
        /**
         * The @RequestMapping annotation takes care of setting the URL
         * this controller will react this.
         */
        @RequestMapping("/accountDetails.htm")
        public ModelAndView accountDetails(HttpServletRequest request) 
        throws ServletRequestBindingException {
            long id = ServletRequestUtils.getRequiredLongParameter(request, "entityId");
            ModelAndView mav = new ModelAndView("accountDetails");
            mav.addObject("account", accountManager.getAccount(id));
            return mav;
        }
     
        @RequestMapping("/accountSummary.htm")
        public ModelAndView accountSummary() {
            List<Account> accounts = accountManager.getAllAccounts();
            ModelAndView mav = new ModelAndView();
            mav.setViewName("accountSummary");
            mav.addObject("accounts", accounts);
            return mav;
        }
    }
    The database is hsqldb.

    Any help or hint would be greatly appreciated it.

    Yours,

    Frustrated.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Spring Mvc 404 error

    What happens if you try this url then?

    http://localhost:8080/accounts/accou...untSummary.htm

    // Json

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Spring Mvc 404 error

    Hi:

    Thank for the reply.
    I figure out what the problem is.
    I have to try http://localhost:8080/account/account/Summary.htm

    because context is account and the web project is account.

    Thank you for your help!!!!

Similar Threads

  1. Recommendations for E commerce web application
    By Desert Fox in forum Web Frameworks
    Replies: 2
    Last Post: November 1st, 2009, 01:31 AM