Simple HelloWorld Application in Springs
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
Test-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="TestController" class="com.springs.TestController"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello.htm">TestController</prop>
</props>
</property>
</bean>
</beans>
hello.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<body>
<h1>Hello <c:out value="${now}"/></h1>
</body>
</html>
TestController.java
package com.springs;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws Exception {
String now = "Prasanthi";
return new ModelAndView("hello.jsp", "now", now);
}
}
1 comment:
Good words.
Post a Comment