addheader

Friday, 12 October 2012

Spring MVC-Annotations say Hai



Spring MVC-Annotations:
---------------------------------------------------------------------

TUTIORALS FROM MADHAV:
 

     JAVA-SERVLETS     JAVA-JDBC     JAVA-JSP       HIBERNATE-SHCEMABASED 

    SPRING-AOP-ANNOTATIONS      SPRING -DAO     SPRIN-MVC     SPRING-SECUTITY

     SPRING-DATA-JPA     REST-WEB-SERVICE     STRUTS2HIBERNATE    GWT.... 




Example program-1:
// this program will describes simple spring –mvc flow.










Index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
<html>
 
  <body>
    This is my JSP page. <br>
    <a href="hai.spring">click hear to call haicontroller</a>
  </body>
</html>

Hai.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
<html>
  <body bgcolor="wheat">
    hai this is madhav <br>welcome to Hugo TC <br>
  </body>
</html>


HaiController.java

package madhav;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.*;

import org.springframework.web.servlet.mvc.*;
import org.springframework.validation.*;
import org.springframework.stereotype.*;
import org.springframework.stereotype.Controller;
import javax.servlet.http.*;
@Controller
public class HaiController
{
@RequestMapping(value="/hai.spring")
      public String sayHai()
      {
                        return  "/Hai.jsp";    
      }
}


Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID">
      <display-name>speingmvcacc</display-name>
 
  <servlet>

<servlet-name>dispatcher</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>dispatcher</servlet-name>

<url-pattern>*.spring</url-pattern>

</servlet-mapping>
<welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


Dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
        http://www.springframework.org/schema/beans    
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

      <context:component-scan base-package="madhav" />

      </beans>
                    
Output-screens:









Click hear to download the above example program


 Related topics:


1.     spring mvc work flow

2.     spring mvc AbstractCommandControllerwork flow

3.     Spring MVC AbstractCommandController -Validation

4.     Spring MVC SimpleFormController workflow

5.     Spring MVC WizardFormController

6.  spring MVC annotations sa hai-mvc flow

7. Spring MVC annotations login validation

8. Spring MVC annotations working with form

 

 

 



No comments:

Post a Comment