Post List

Friday, July 29, 2016

2. Spring MVC - Hello World example




1. Create a Maven Project

- File > New > Maven Project
- Select maven-archetype-webapp
- Enter an groupId and artifactId

ex) groupId : com.yunjee.springmvc / artifactId : SpringWeb

- Guide to naming
  https://maven.apache.org/guides/mini/guide-naming-conventions.html



2. Modify pom.xml

 Change pom.xml file to be the following :


3. Create web.xml

- Create webapp/WEB-INF/web.xml file to be the following :


4. Create ooo-servlet.xml


- Create webapp/WEB-INF/spring-servlet.xml file to be the following :


5. Create a JSP Page

- File > New > JSP file : webapp/WEB-INF/views/welcome.jsp
welcome.jsp file to be the following :


6. Create a Java Class

- File > New > Package > com.yunjee.spring
- File > New > Class > HelloWorldController.java
- HelloWorldController.java file to be the following :


7. Set a Server

- Window > show view > Server
- Create server > Select available project


8. Execute

- Run > Run (Ctrl + F11)
















** Error

The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

- Check below Properties if tomcat is set

  • Java Build Path > add Library.. 
  • Targeted Runtimes
  • Project Facets > Runtimes

- Or, add servlet-api in Java Build Path > Libraries



** Refer
http://spring.io/projects
- http://www.tutorialspoint.com/spring/spring_hello_world_example.htm
- http://www.programcreek.com/2012/06/spring-framework-tutorial-hello-world/

No comments :

Post a Comment