diff --git a/spring-mvc-handlers/pom.xml b/spring-mvc-handlers/pom.xml new file mode 100644 index 0000000000..0074898767 --- /dev/null +++ b/spring-mvc-handlers/pom.xml @@ -0,0 +1,70 @@ + + 4.0.0 + com.baeldung + SpringMVCHandlers + war + 0.0.1-SNAPSHOT + SpringMVCHandlers Maven Webapp + http://maven.apache.org + + + 4.3.4.RELEASE + 3.5.1 + 2.6 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + commons-logging + commons-logging + 1.2 + + + org.springframework + spring-webmvc + ${springframework.version} + + + org.springframework + spring-context + ${springframework.version} + + + org.springframework + spring-core + ${springframework.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + src/main/webapp + springMVCHandlers + false + + + + + springMVCHandlers + + diff --git a/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java b/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java new file mode 100644 index 0000000000..164830cd6a --- /dev/null +++ b/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class AnnotationMethodHandlerAdapterExample { + @RequestMapping("/annotedName") + public ModelAndView getEmployeeName() { + ModelAndView model = new ModelAndView("Greeting"); + model.addObject("message", "Dinesh"); + return model; + } +} \ No newline at end of file diff --git a/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java b/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java new file mode 100644 index 0000000000..76ac3e2806 --- /dev/null +++ b/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class RequestMappingHandlerAdapterExample { + @RequestMapping("/requestName") + public ModelAndView getEmployeeName() { + ModelAndView model = new ModelAndView("Greeting"); + model.addObject("message", "Madhwal"); + return model; + } +} \ No newline at end of file diff --git a/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java b/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java new file mode 100644 index 0000000000..48ece758a9 --- /dev/null +++ b/spring-mvc-handlers/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java @@ -0,0 +1,18 @@ +package com.baeldung.spring.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.AbstractController; + +public class SimpleControllerHandlerAdapterExample extends + AbstractController { + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest arg0, + HttpServletResponse arg1) throws Exception { + ModelAndView model = new ModelAndView("Greeting"); + model.addObject("message", "Dinesh Madhwal"); + return model; + } +} \ No newline at end of file diff --git a/spring-mvc-handlers/src/main/resources/spring-servlet_AnnotationMethodHandlerAdapter.xml b/spring-mvc-handlers/src/main/resources/spring-servlet_AnnotationMethodHandlerAdapter.xml new file mode 100644 index 0000000000..a8071a622f --- /dev/null +++ b/spring-mvc-handlers/src/main/resources/spring-servlet_AnnotationMethodHandlerAdapter.xml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-handlers/src/main/resources/spring-servlet_RequestMappingHandlerAdapter.xml b/spring-mvc-handlers/src/main/resources/spring-servlet_RequestMappingHandlerAdapter.xml new file mode 100644 index 0000000000..b32a213eb3 --- /dev/null +++ b/spring-mvc-handlers/src/main/resources/spring-servlet_RequestMappingHandlerAdapter.xml @@ -0,0 +1,28 @@ + + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-handlers/src/main/resources/spring-servlet_SimpleControllerHandlerAdapter.xml b/spring-mvc-handlers/src/main/resources/spring-servlet_SimpleControllerHandlerAdapter.xml new file mode 100644 index 0000000000..60c9b9e3df --- /dev/null +++ b/spring-mvc-handlers/src/main/resources/spring-servlet_SimpleControllerHandlerAdapter.xml @@ -0,0 +1,25 @@ + + + + + + + + + \ No newline at end of file diff --git a/spring-mvc-handlers/src/main/webapp/WEB-INF/Greeting.jsp b/spring-mvc-handlers/src/main/webapp/WEB-INF/Greeting.jsp new file mode 100644 index 0000000000..820d2f380f --- /dev/null +++ b/spring-mvc-handlers/src/main/webapp/WEB-INF/Greeting.jsp @@ -0,0 +1,5 @@ + + +

Hello ${message}

+ + \ No newline at end of file diff --git a/spring-mvc-handlers/src/main/webapp/WEB-INF/web.xml b/spring-mvc-handlers/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..b6f1065cad --- /dev/null +++ b/spring-mvc-handlers/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + spring + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath*:spring-servlet_RequestMappingHandlerAdapter.xml + + 1 + + + spring + / + + \ No newline at end of file