reset password
Author Message
cysun
Posts: 2935
Posted 14:06 Dec 14, 2009 |

Creating a web application using Spring and Hibernate is quite simple - the trick is to know what files are needed and which folders they should go to. Here's an example of creating a Spring-based HelloWorld web application using Eclipse:

1. Create a Dynamic Web Project in Eclipse.

2. Copy all the necessary library jar files to WEB-INF/lib.

3. Add the Spring dispatcher servlet to web.xml:

    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

4. Create a controller.

5. Create a JSP, i.e. view.

6. Create the Spring bean definition file hello-servlet.xml under WEB-INF. Note that the name of this file must be in the form of <dispatcher-servlet-name>-servlet.xml, i.e. it has to match the name of the dispatcher servlet specified in web.xml.

7. In hello-servlet.xml, add the following:

  • A bean for controller URL mapping.
  • A bean for view resolution.
  • A bean for the controller.

8. Run the project.

Note that unlike in CSNS, you do not need to "refresh project" because Eclipse automatically detects changes to the files under /src and /WebContent.

niteenborge
Posts: 7
Posted 14:31 Dec 14, 2009 |

Thank you Dr Sun, for this information...