Results 1 to 2 of 2

Thread: Spring MVC

  1. #1
    vitaliy1901 is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Spring MVC

    Hi every one! I have been learning spring mvc, but I get error page 404 when I started tomcat server and went to URL http://localhost:8080/HelloWorld/welcome.htm. What's wrong with my code or structure? Thanks for help!

    # my structure:
    Spring MVC-1.jpg

    # HelloWorldController.java
    Java Code:
    package controller;
    
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.AbstractController;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class HelloWorldController extends AbstractController{
    
        @Override
        protected ModelAndView handleRequestInternal(HttpServletRequest request,
                                                     HttpServletResponse response) throws Exception {
    
            ModelAndView model = new ModelAndView("HelloWorldPage");
            model.addObject("msg", "hello world");
    
            return model;
        }
    }
    # web.xml
    Java Code:
    <web-app id="WebApp_ID" version="2.4"
    	xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
    	<display-name>Spring Web MVC Application</display-name>
    
    	<servlet>
    		<servlet-name>mvc-dispatcher</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>mvc-dispatcher</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    	</context-param>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    </web-app>
    # mvc-dispatcher-servlet.xml
    Java Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix">
    			<value>/WEB-INF/pages/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    
    	<bean name="/welcome.htm" 
    		class="controller.HelloWorldController" />
    
    </beans>

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Spring MVC

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. new to spring mvc with JPA
    By javastuden in forum New To Java
    Replies: 0
    Last Post: 07-26-2011, 09:25 AM
  2. spring with jpa help please help me
    By javastuden in forum Advanced Java
    Replies: 0
    Last Post: 07-08-2011, 04:41 PM
  3. Spring IoC
    By videanuadrian in forum Advanced Java
    Replies: 6
    Last Post: 07-08-2011, 10:42 AM
  4. Replies: 1
    Last Post: 12-27-2010, 05:21 PM
  5. spring mvc
    By karq in forum Advanced Java
    Replies: 0
    Last Post: 12-13-2010, 04:28 PM

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
  •