Rename to spring-mvc-simple
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
ModelAndView model = new ModelAndView("Greeting");
|
||||
model.addObject("message", "Dinesh Madhwal");
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||
<context:component-scan base-package="com.baeldung.spring.controller" />
|
||||
<bean
|
||||
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
|
||||
<bean
|
||||
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
|
||||
<bean id="viewResolver"
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/WEB-INF/" />
|
||||
<property name="suffix" value=".jsp" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||
<context:component-scan base-package="com.baeldung.spring.controller" />
|
||||
<bean
|
||||
class=
|
||||
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
|
||||
<bean
|
||||
class=
|
||||
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
|
||||
<bean id="viewResolver"
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/WEB-INF/" />
|
||||
<property name="suffix" value=".jsp" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||
<bean id="HandlerMapping"
|
||||
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
|
||||
<bean name="/greeting.html"
|
||||
class="com.baeldung.spring.controller.SimpleControllerHandlerAdapterExample"/>
|
||||
<bean id="viewResolver"
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/WEB-INF/" />
|
||||
<property name="suffix" value=".jsp" />
|
||||
</bean>
|
||||
</beans>
|
||||
5
spring-mvc-simple/src/main/webapp/WEB-INF/Greeting.jsp
Normal file
5
spring-mvc-simple/src/main/webapp/WEB-INF/Greeting.jsp
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>Hello ${message}</h1>
|
||||
</body>
|
||||
</html>
|
||||
19
spring-mvc-simple/src/main/webapp/WEB-INF/web.xml
Normal file
19
spring-mvc-simple/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
||||
<servlet>
|
||||
<servlet-name>spring</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath*:spring-servlet_RequestMappingHandlerAdapter.xml</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>spring</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
Reference in New Issue
Block a user