You can view the tutorials best in Google Chrome, Mozilla Firefox, Opera, higher version of Internet Explorer

Spring MVC Hello World, Spring MVC 3.2 Hello World Example In Eclipse

Spring-MVC » On Jul 14, 2013 By Sivateja

Let us execute spring MVC hello world application with complete explanation, will see it in an eclipse :-)

Open eclipse > File  > Dynamic Web Project

Give Project Name > Finish

Directory Structure

Required Files

  • Java4sController.java
  • welcomePage.jsp
  • web.xml
  • welcome-servlet.xml
  • index.jsp

index.jsp

web.xml

Java4sController.java

welcome-servlet.xml

welcomePage.jsp

Execution Flow

  • Run the application, then index.jsp file will be executed > click on the link given (I have given <a href=”java4s.html”>Click here to check the output :-)</a>)
  • Once you click on that link, container will check the URL pattern at web.xml and passes the request to the DispatcherServlet
  • DispatcherServlet then passes that request to our controller class
  • Actually we are passing java4s.html from index.jsp right ? so DispatcherServlet verifies this ‘java4s’ name with the string in @RequestMapping(“-”) in our controller class if same it will executes the following method, which gives ModelAndView object as return type

In our controller class we are returning…

Means first argument is ‘View’ page name [ Where we are sending our result ], second, third arguments are key,values

  • So DispatcherServlet search for the name welcomePage in /jsp folder with extension .jsp [ you can change the 'view page' folder name/location and its extension in welcome-servlet.xml at line numbers 14,15],  once the file was opened you can access the data by using the key welcomeMessage [2nd parameter in ModelAndView object]
  • Check welcomePage.jsp > i am printing the result by calling the key ${welcomeMessage}

Note

  • In web.xml we have given servlet name as welcome, so spring configuration file name must be welcome-servlet.xml [ {servletName-in-web.xml}-servlet.xml ]

Output






By [ Java/J2EE Developer & Web Designer ]
Founder of Java4s.com - Indian, lives in United States. You can contact me at sivateja [at] java4s.com
Follow me on


Comments

13 Responses to “Spring MVC Hello World, Spring MVC 3.2 Hello World Example In Eclipse”
  1. ramana says:

    i am trying to execute Spring MVC Hello World program in Dynamic web project using eclipise it is rising java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor.(Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/PropertyResolver;)

  2. GSolanki says:

    you should first explain the annotations such as @controller….,@requestmapping….
    you got it right

  3. B.Prasad says:

    what is the difference between comparable and comparator interfaces and give me one real time example please

  4. utkal samal says:

    HI ,
    I am sending the request from index.jsp as only java4s, but request is not happening,Could You please suggest me, why it is not happening ?????

  5. Prasanth says:

    Thank you , it is really helpful.

  6. Saroj Kumar says:

    In index.html, you have given “java4s.html” as href, but in controller class, you have given “/java4s” as parameter in @RequestMapping.
    You haven’t explain about how this is working.
    Please explain the same.

    Thanks.

  7. Deepak Kumar says:

    Hi,

    Please add missing spring-aop-x.x.x.RELEASE.jar into WEB-INF\web folder. This will help you to run the above program without errors.

    Thanks
    Deepak Kumar

  8. prashant says:

    how to upload any pdf,image and store in MySql

  9. Loganathan says:

    Thank you so much. Really its makes me to understand the springflow very clearly. Once again thanks.

  10. Hi, Earlier I ran this example successfully. But now I am getting 404 error after clicking on a href link. Can u plz suggest.

    please note- I am just trying the example given above. I didn’t do any changes.

  11. Sachin says:

    Nice Explanation yar….

  12. hari krishna says:

    When i ran this example i am getting the below exception . Please assist.

    No mapping found for HTTP request with URI [/Spring_MVC/java4s.html] in DispatcherServlet with name ‘welcome’

  13. Dushyanth says:

    Hi,

    I see the warning : No mapping found for HTTP request with URI [/Mvc/] in DispatcherServlet with name ‘welcome’. How to overcome this ??

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links
Current & UpComing Tutorials
Sitemap :
spring Hibernate struts Json Ajax Log4j Log4j coreJava Servlets Web Services


Upcoming
  Web Services [ In Progress ], JSP
Facebook_Java4s  Twitter_Java4s  GooglePlus_Java4s  Youtube_Java4s 
© 2010 - 2014 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.