Lara

 

Spring

 

Saturday(11-02-2017 )                                                                                                                    app1

test1.jsp

<a href="hello1">Hello1</a>

success1.jsp

this is success1.jsp

 package com.lara;

 

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

@Controller

public class HelloController

{

            @RequestMapping(value="/hello1",

                                    method=RequestMethod.GET)

            public String processHello1()

            {

                        System.out.println("i am from processHello1");

                        return "success1.jsp";

            }

}

config-servlet.xml

<?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:context="http://www.springframework.org/schema/context"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context.xsd

                        http://www.springframework.org/schema/mvc

        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

 

    <context:annotation-config/>

    <context:component-scan base-package="com.lara"/>

    <mvc:annotation-driven/>

 

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>app1</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

 

            <servlet>

                        <servlet-name>config</servlet-name>

                        <servlet-class>

                                    org.springframework.web.servlet.DispatcherServlet

                        </servlet-class>

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

            </servlet>

 

            <servlet-mapping>

                        <servlet-name>config</servlet-name>

                        <url-pattern>/</url-pattern>    

            </servlet-mapping>

  </web-app>

app2

test1.jsp

<a href="hello1">Hello1</a> </br>

 

success1.jsp

this is success1.jsp

test2.jsp

<form action="hello2">

            <input type='submit' value='submit'/>

</form>

success2.jsp

i am from success2.jsp

test3.jsp

<form action="hello3" method="post">

            <input type='submit' value='submit'/>

</form>

 

success3.jsp

this is from success3.jsp

 

test4.jsp

<a href="hello4?param1=abc&param2=xyz">Hello4</a>

 

success4.jsp

this is success4.jsp </br>

 

${param.param1}  </br>

${param.param2}  </br>

-----=---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

test5.jsp

<form action="hello5" method="post">

            First Name : <input type='text' name='firstName'/> </br>

            Last Name : <input type='text' name='lastName'/> </br>

            <input type='submit' value='submit'/>

</form>

 

success5.jsp

this is success5.jsp </br>

 

${param.firstName}  </br>

${param.lastName}  </br>

test6.jsp

<a href="hello6">Hello6</a>

 

success6.jsp

I am from success6.jsp

 

 

test7.jsp

<a href="hello7">Hello7</a>

 

success7.jsp

this is from success7.jsp</br>

 

${key1}  </br>

${firstName} </br>

${age}

test8.jsp

<a href="hello8">Hello8</a>

 

success8.jsp

this is from success8.jsp</br>

 

${key1}  </br>

${firstName} </br>

${age}

test9.jsp

<%@ taglib prefix="s" uri="http://www.springframework.org/tags/form" %>

<s:form commandName="hello9Command">

            First Name: <s:input path="firstName"/> </br>

            Last Name: <s:input path="lastName"/> </br>

            <input type='submit' value='submit'/>

</s:form>

 

success9.jsp

This is from success9.jsp</br>

 

${hello9Command.firstName} </br>

${hello9Command.lastName} </br>

test10.jsp

<%@ taglib prefix="s" uri="http://www.springframework.org/tags/form" %>

 

 

<s:form commandName="hello10Command">

            First Name: <s:input path="firstName"/> </br>

            Age: <s:input path="age"/> </br>

            Email: <s:input path="email"/> </br>

            <input type='submit' value='submit'/>

</s:form>

 

 

success10.jsp

This is success10.jsp

 

${hello10Command.firstName} </br>

${hello10Command.age} </br>

${hello10Command.email} </br>

package com.lara;

 

public class Person

{

            private String firstName;

            private String lastName;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public String getLastName()

            {

                        return lastName;

            }

            public void setLastName(String lastName)

            {

                        this.lastName = lastName;

            }

           

}

package com.lara;

 

public class Student

{

            private String firstName;

            private Integer age;

            private String email;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public Integer getAge()

            {

                        return age;

            }

            public void setAge(Integer age)

            {

                        this.age = age;

            }

            public String getEmail()

            {

                        return email;

            }

            public void setEmail(String email)

            {

                        this.email = email;

            }

 

           

           

}

package com.lara;

 

import java.util.Map;

 

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

@Controller

public class HelloController

{

            @RequestMapping(value="/hello1", method=RequestMethod.GET)

            public String processHello1()

            {

                        System.out.println("from processHello1");

                        return "success1.jsp";

            }

            @RequestMapping(value="/hello2", method=RequestMethod.GET)

            public String processHello2()

            {

                        System.out.println("from processHello2");

                        return "success2.jsp";

            }          

            @RequestMapping(value="/hello3", method=RequestMethod.POST)

            public String processHello3()

            {

                        System.out.println("from processHello3");

                        return "success3.jsp";

            }          

            @RequestMapping(value="/hello4", method=RequestMethod.GET)

            public String processHello4(HttpServletRequest request)

            {

                        String s1 = request.getParameter("param1");

                        String s2 = request.getParameter("param2");

                        System.out.println("from processHello4");

                        System.out.println(s1);

                        System.out.println(s2);               

                        return "success4.jsp";

            }                      

            @RequestMapping(value="/hello5", method=RequestMethod.POST)

            public String processHello5(HttpServletRequest request)

            {

                        String s1 = request.getParameter("firstName");

                        String s2 = request.getParameter("lastName");

                        System.out.println("from processHello5");

                        System.out.println(s1);

                        System.out.println(s2);               

                        return "success5.jsp";

            }                                  

           

            @RequestMapping(value="/hello6", method=RequestMethod.GET)

            public String processHello6(HttpServletResponse response)

            {

                        response.setIntHeader("refresh", 10);

                        System.out.println("from processHello6");

                        return "success6.jsp";

            }          

            @RequestMapping(value="/hello7", method=RequestMethod.GET)

            public String processHello7(Map map)

            {

                        map.put("key1", "value1");

                        map.put("firstName", "Ramu");

                        map.put("age", 33);

                        System.out.println("from processHello7");

                        return "success7.jsp";

            }

            @RequestMapping(value="/hello8", method=RequestMethod.GET)

            public String processHello8(ModelMap map)

            {

                        map.put("key1", "value1");

                        map.put("firstName", "Ramu");

                        map.put("age", 33);

                        System.out.println("from processHello8");

                        return "success8.jsp";

            }                      

            @RequestMapping(value="/hello9", method=RequestMethod.GET)

            public String getViewForHello9(ModelMap map)

            {

                        System.out.println("from getViewForHello9");

                        map.put("hello9Command", new Person());

                        return "test9.jsp";

            }          

            @RequestMapping(value="/hello9", method=RequestMethod.POST)

            public String processHello9(@ModelAttribute("hello9Command")Person person)

            {

                        System.out.println("from processHello9");

                        System.out.println(person.getFirstName());

                        System.out.println(person.getLastName());

                        return "success9.jsp";

            }          

 

            @RequestMapping(value="/hello10", method=RequestMethod.GET)

            public String getViewForHello10(ModelMap map)

            {

                        System.out.println("from getViewForHello10");

                        map.put("hello10Command", new Student());

                        return "test10.jsp";

            }          

            @RequestMapping(value="/hello10", method=RequestMethod.POST)

            public String processHello10(@ModelAttribute("hello10Command")Student st)

            {

                        System.out.println("from processHello10");

                        System.out.println(st.getFirstName());

                        System.out.println(st.getAge());

                        System.out.println(st.getEmail());

                        return "success10.jsp";

            }                      

 

}

controller-servlet.xml

<?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:context="http://www.springframework.org/schema/context"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context.xsd

        http://www.springframework.org/schema/mvc

        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

            <context:component-scan base-package="com.lara"/>

    <context:annotation-config/>

    <mvc:annotation-driven/>

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>app2</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

            <servlet>

                        <servlet-name>controller</servlet-name>

                        <servlet-class>

                                    org.springframework.web.servlet.DispatcherServlet

                        </servlet-class>

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

            </servlet>

 

            <servlet-mapping>

                        <servlet-name>controller</servlet-name>

                        <url-pattern>/</url-pattern>    

            </servlet-mapping>

 

</web-app>

 

Sunday(12-02-2017)

pagesàtest11.jsp

<%@ taglib prefix="s" uri="http://www.springframework.org/tags/form" %>

 

 

<s:form commandName="hello11Command">

            First Name: <s:input path="firstName"/> </br>

            Age: <s:input path="age"/> </br>

            Email: <s:input path="email"/> </br>

            <input type='submit' value='submit'/>

</s:form>

pagesàsuccess11.jsp

This is success11.jsp

 

${hello11Command.firstName} </br>

${hello11Command.age} </br>

${hello11Command.email} </br>

pagesàtest12.jsp

<%@ taglib prefix="s" uri="http://www.springframework.org/tags/form" %>

 

 

<s:form commandName="hello12Command">

            First Name : <s:input path="firstName"/> </br>

            Last Name : <s:input path="lastName"/> </br>

            <input type='submit' value='submit'/>

</s:form>

pagesàsuccess12.jsp

This is success12.jsp

 

${hello12Command.firstName} </br>

${hello12Command.lastName} </br>

pagesàtest13.jsp

<%@ taglib prefix="c" uri="http://www.springframework.org/tags" %>

<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form" %>

 

 

<f:form commandName="hello13Command">

            <c:message code="firstName"/>

            <f:input path="firstName"/> </br>

            <c:message code="lastName"/>

            <f:input path="lastName"/> </br>

            <input type='submit' value='submit'/>

</f:form>

pagesàsuccess13.jsp

<%@ taglib prefix="c" uri="http://www.springframework.org/tags" %>

 

<c:message code="test13.success"/>

 

${hello13Command.firstName} </br>

${hello13Command.lastName} </br>

pagesàtest14.jsp

<%@ taglib prefix="c" uri="http://www.springframework.org/tags" %>

<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form" %>

 

 

<f:form commandName="hello14Command" enctype="multipart/form-data">

            <c:message code="firstName"/>

            <f:input path="firstName"/> </br>

            <c:message code="lastName"/>

            <f:input path="lastName"/> </br>

            <c:message code="picture"/>

            <input type="file" name="pic"/>

            <input type='submit' value='submit'/>

</f:form>

pagesàsuccess14.jsp

this is success14.jsp

package com.lara;

 

import java.io.IOException;

import java.util.Map;

 

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

@Controller

public class HelloController

{

            @RequestMapping(value="/hello1", method=RequestMethod.GET)

            public String processHello1()

            {

                        System.out.println("from processHello1");

                        return "success1.jsp";

            }

            @RequestMapping(value="/hello2", method=RequestMethod.GET)

            public String processHello2()

            {

                        System.out.println("from processHello2");

                        return "success2.jsp";

            }          

            @RequestMapping(value="/hello3", method=RequestMethod.POST)

            public String processHello3()

            {

                        System.out.println("from processHello3");

                        return "success3.jsp";

            }          

            @RequestMapping(value="/hello4", method=RequestMethod.GET)

            public String processHello4(HttpServletRequest request)

            {

                        String s1 = request.getParameter("param1");

                        String s2 = request.getParameter("param2");

                        System.out.println("from processHello4");

                        System.out.println(s1);

                        System.out.println(s2);               

                        return "success4.jsp";

            }                      

            @RequestMapping(value="/hello5", method=RequestMethod.POST)

            public String processHello5(HttpServletRequest request)

            {

                        String s1 = request.getParameter("firstName");

                        String s2 = request.getParameter("lastName");

                        System.out.println("from processHello5");

                        System.out.println(s1);

                        System.out.println(s2);               

                        return "success5.jsp";

            }                                  

           

            @RequestMapping(value="/hello6", method=RequestMethod.GET)

            public String processHello6(HttpServletResponse response)

            {

                        response.setIntHeader("refresh", 10);

                        System.out.println("from processHello6");

                        return "success6.jsp";

            }          

            @RequestMapping(value="/hello7", method=RequestMethod.GET)

            public String processHello7(Map map)

            {

                        map.put("key1", "value1");

                        map.put("firstName", "Ramu");

                        map.put("age", 33);

                        System.out.println("from processHello7");

                        return "success7.jsp";

            }

            @RequestMapping(value="/hello8", method=RequestMethod.GET)

            public String processHello8(ModelMap map)

            {

                        map.put("key1", "value1");

                        map.put("firstName", "Ramu");

                        map.put("age", 33);

                        System.out.println("from processHello8");

                        return "success8.jsp";

            }                      

            @RequestMapping(value="/hello9", method=RequestMethod.GET)

            public String getViewForHello9(ModelMap map)

            {

                        System.out.println("from getViewForHello9");

                        map.put("hello9Command", new Person());

                        return "test9.jsp";

            }          

            @RequestMapping(value="/hello9", method=RequestMethod.POST)

            public String processHello9(@ModelAttribute("hello9Command")Person person)

            {

                        System.out.println("from processHello9");

                        System.out.println(person.getFirstName());

                        System.out.println(person.getLastName());

                        return "success9.jsp";

            }          

 

            @RequestMapping(value="/hello10", method=RequestMethod.GET)

            public String getViewForHello10(ModelMap map)

            {

                        System.out.println("from getViewForHello10");

                        map.put("hello10Command", new Student());

                        return "test10.jsp";

            }          

            @RequestMapping(value="/hello10", method=RequestMethod.POST)

            public String processHello10(@ModelAttribute("hello10Command")Student st)

            {

                        System.out.println("from processHello10");

                        System.out.println(st.getFirstName());

                        System.out.println(st.getAge());

                        System.out.println(st.getEmail());

                        return "success10.jsp";

            }                      

           

            @RequestMapping(value="/hello11", method=RequestMethod.GET)

            public String getViewForHello11(ModelMap map)

            {

                        System.out.println("from getViewForHello11");

                        map.put("hello11Command", new Student());

                        return "test11";

            }          

            @RequestMapping(value="/hello11", method=RequestMethod.POST)

            public String processHello11(@ModelAttribute("hello11Command")Student st)

            {

                        System.out.println("from processHello11");

                        System.out.println(st.getFirstName());

                        System.out.println(st.getAge());

                        System.out.println(st.getEmail());

                        return "success11";

            }                      

           

            @RequestMapping(value="/hello12", method=RequestMethod.GET)

            public String getViewForHello12(ModelMap map)

            {

                        System.out.println("from getViewForHello12");

                        map.put("hello12Command", new Employee());

                        return "test12";

            }          

            @RequestMapping(value="/hello12", method=RequestMethod.POST)

            public String processHello12(@ModelAttribute("hello12Command")Employee st)

            {

                        System.out.println("from processHello12");

                        System.out.println(st.getFirstName());

                        System.out.println(st.getLastName());

                        return "success12";

            }                                  

           

           

            @RequestMapping(value="/hello13", method=RequestMethod.GET)

            public String getViewForHello13(ModelMap map)

            {

                        System.out.println("from getViewForHello13");

                        map.put("hello13Command", new Employee());

                        return "test13";

            }          

            @RequestMapping(value="/hello13", method=RequestMethod.POST)

            public String processHello13(@ModelAttribute("hello13Command")Employee st)

            {

                        System.out.println("from processHello13");

                        System.out.println(st.getFirstName());

                        System.out.println(st.getLastName());

                        return "success13";

            }                                  

           

           

           

            @RequestMapping(value="/hello14", method=RequestMethod.GET)

            public String getViewForHello14(ModelMap map)

            {

                        System.out.println("from getViewForHello14");

                        map.put("hello14Command", new Customer());

                        return "test14";

            }          

            @RequestMapping(value="/hello14", method=RequestMethod.POST)

            public String processHello14(@ModelAttribute("hello14Command")Customer st)

            {

                        System.out.println("from processHello14");

                        System.out.println(st.getFirstName());

                        System.out.println(st.getLastName());

                        System.out.println(st.getPic().getOriginalFilename());

                        try

                        {

                                    System.out.println(st.getPic().getBytes().length);

                        }

                        catch(IOException ex)

                        {

                                    ex.printStackTrace();

                        }                      

                        return "success14";

            }                                  

 

}

package com.lara;

 

public class Employee

{

            private String firstName;

            private String lastName;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public String getLastName()

            {

                        return lastName;

            }

            public void setLastName(String lastName)

            {

                        this.lastName = lastName;

            }

}

package com.lara;

 

import org.springframework.web.multipart.MultipartFile;

 

public class Customer

{

            private String firstName;

            private String lastName;

            private MultipartFile pic;

           

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public String getLastName()

            {

                        return lastName;

            }

            public void setLastName(String lastName)

            {

                        this.lastName = lastName;

            }

            public MultipartFile getPic()

            {

                        return pic;

            }

            public void setPic(MultipartFile pic)

            {

                        this.pic = pic;

            }

           

}

messages.properites

firstName=First Name

lastName=Last Name

test13.success=This is from success13.jsp.

picture=Picture

 

controller-servlet.xml

<?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:context="http://www.springframework.org/schema/context"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context.xsd

        http://www.springframework.org/schema/mvc

        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

            <context:component-scan base-package="com.lara"/>

    <context:annotation-config/>

    <mvc:annotation-driven/>

            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

                        <property name="prefix" value="/WEB-INF/pages/"/>

                        <property name="suffix" value=".jsp"/>

            </bean> 

   <bean id="messageSource"

         class="org.springframework.context.support.ResourceBundleMessageSource">

                        <property name="basename" value="messages"/>     

   </bean>    

            <bean id="multipartResolver"

                    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

                <property name="maxUploadSize" value="100000"/>

            </bean>       

 

</beans>

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>app2</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

 

            <servlet>

                        <servlet-name>controller</servlet-name>

                        <servlet-class>

                                    org.springframework.web.servlet.DispatcherServlet

                        </servlet-class>

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

            </servlet>

            <servlet-mapping>

                        <servlet-name>controller</servlet-name>

                        <url-pattern>/</url-pattern>    

            </servlet-mapping>

           

<!--     <listener> -->

<!--         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> -->

<!--     </listener>   -->

 

 

</web-app>

-----=-----------------------------------------------------------------

 

 Saturday(18-02-2017)

Index.jsp

<a href="registration">New User</a>

<a href="login">Login</a>

pages-login.jsp

<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>

<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form" %>

 

<f:form commandName="loginForm">

                <s:message code="loginForm.username"/>

                <f:input path="username"/>

                <f:errors path="username"/>

                </br>

                <s:message code="loginForm.password"/>

                <f:input path="password"/>

                <f:errors path="password"/>

                </br>

                <input type="submit"/>

</f:form>

pages—loginSuccess.jsp

this is loginSuccess

pages—reg.jsp

<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>

<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form" %>

 

 

 

<f:form commandName="regForm">

            <s:message code="regForm.firstName"/>

            <f:input path="firstName"/>

            <f:errors path="firstName"/>

            </br>

 

            <s:message code="regForm.lastName"/>

            <f:input path="lastName"/>

            <f:errors path="lastName"/>

             </br>

 

            <s:message code="regForm.age"/>

            <f:input path="age"/>

            <f:errors path="age"/>

             </br>

 

            <s:message code="regForm.email"/>

            <f:input path="email"/>

            <f:errors path="email"/>

             </br>

 

            <input type="submit" value="submit"/>

</f:form>

pages—regSuccess.jsp

this is regSuccess

package com.lara;

 

public class RegistrationUser

{

            private String firstName;

            private String lastName;

            private Integer age;

            private String email;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public String getLastName()

            {

                        return lastName;

            }

            public void setLastName(String lastName)

            {

                        this.lastName = lastName;

            }

            public Integer getAge()

            {

                        return age;

            }

            public void setAge(Integer age)

            {

                        this.age = age;

            }

            public String getEmail()

            {

                        return email;

            }

            public void setEmail(String email)

            {

                        this.email = email;

            }

           

}

package com.lara;

 

import org.springframework.validation.Errors;

import org.springframework.validation.Validator;

 

public class RegistrationValidator implements Validator

{

            @Override

            public boolean supports(Class<?> arg0)

            {

                        return arg0.equals(RegistrationUser.class);

            }

           

            @Override

            public void validate(Object arg0, Errors arg1)

            {

                        RegistrationUser regUser = (RegistrationUser) arg0;

                        String s1 = regUser.getFirstName();

                        if(s1 == null || s1.length() == 0)

                        {

                                    arg1.rejectValue("firstName", "regForm.firstName.required", "First Name is required one");

                        }

                        String s2 = regUser.getLastName();

                        if(s2 == null || s2.length() == 0)

                        {

                                    arg1.rejectValue("lastName", "regForm.lastName.required", "Last Name is required one");

                        }

                        Integer s3 = regUser.getAge();

                        if(s3 == null || s3.toString().length() == 0)

                        {

                                    arg1.rejectValue("age", "regForm.age.required", "Age is required one");

                        }

                        String s4 = regUser.getEmail();

                        if(s4 == null || s4.length() == 0)

                        {

                                    arg1.rejectValue("email", "regForm.email.required", "Email is required one");

                        }

 

 

           

            }

           

           

}

package com.lara;

 

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

import org.springframework.validation.BindingResult;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

@Controller

public class RegistrationController

{

            @RequestMapping(path="/registration", method=RequestMethod.GET)

            public String getViewForReg(ModelMap map)

            {

                        map.put("regForm", new RegistrationUser());

                        return "reg";

            }

           

            @RequestMapping(path="/registration", method=RequestMethod.POST)

            public String processReg(@ModelAttribute(value="regForm")

                                                                                     RegistrationUser command,

                                                                                     BindingResult errors,

                                                                                     ModelMap map)

            {

                        RegistrationValidator validator = new RegistrationValidator();

                        validator.validate(command, errors);

                        if(errors.hasErrors())

                        {

                                    map.put("regForm", command);

                                    return "reg";

                        }

                        System.out.println(command.getFirstName());

                        System.out.println(command.getLastName());

                        System.out.println(command.getAge());

                        System.out.println(command.getEmail());

                        return "regSuccess";

            }

           

}

package com.lara;

 

public class LoginUser

{

            private String username;

            private String password;

            public String getUsername()

            {

                        return username;

            }

            public void setUsername(String username)

            {

                        this.username = username;

            }

            public String getPassword()

            {

                        return password;

            }

            public void setPassword(String password)

            {

                        this.password = password;

            }

           

}

package com.lara;

 

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

import org.springframework.validation.BindingResult;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

@Controller

public class LoginController

{

            @RequestMapping(value="/login", method=RequestMethod.GET)

            public String getLoginView(ModelMap map)

            {

                        map.put("loginForm", new LoginUser());

                        return "login";

            }

           

           

            @RequestMapping(value="/login", method=RequestMethod.POST)

            public String processLogin(@ModelAttribute(value="loginForm")

                                                                                       LoginUser user,

                                                                                       BindingResult errors,

                                                                                       ModelMap map)

            {

                        LoginValidator validator = new LoginValidator();

                        validator.validate(user, errors);

                        if(errors.hasErrors())

                        {

                                    map.put("loginForm", user);

                                    return "login";

                        }

                        System.out.println(user.getUsername());

                        System.out.println(user.getPassword());

                        return "loginSuccess";

            }

}

package com.lara;

 

import org.springframework.validation.Errors;

import org.springframework.validation.Validator;

 

public class LoginValidator implements Validator

{

            @Override

            public boolean supports(Class<?> arg0)

            {

                        return arg0.equals(LoginUser.class);

            }

            @Override

            public void validate(Object arg0, Errors arg1)

            {

                        LoginUser user = (LoginUser) arg0;

                        String s1 = user.getUsername();

                        if(s1 == null || s1.length() == 0)

                        {

                                    arg1.rejectValue("username", "loginForm.username.required", "username is required one");

                        }

                        String s2 = user.getPassword();

                        if(s2 == null || s2.length() == 0)

                        {

                                    arg1.rejectValue("password", "loginForm.password.required", "password is required one");

                        }

            }

           

}

messages.properties

regForm.firstName=First Name

regForm.lastName=Last Name

regForm.age=Age

regForm.email=Email

regForm.firstName.required=First Name is mandatory. please enter it

regForm.lastName.required=Last Name is mandatory. please enter it

regForm.email.required=Email is mandatory. please enter it

loginForm.username=Username

loginForm.password=Password

loginForm.username.required=Username is mandatory. pls enter it

loginForm.password.required=Password is mandatory. pls enter it

controller-servlet.xml

<?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:context="http://www.springframework.org/schema/context"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context.xsd

        http://www.springframework.org/schema/mvc

        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

            <context:component-scan base-package="com.lara"/>

    <context:annotation-config/>

    <mvc:annotation-driven/>

            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

                        <property name="prefix" value="/WEB-INF/pages/"/>

                        <property name="suffix" value=".jsp"/>

            </bean> 

   <bean id="messageSource"

         class="org.springframework.context.support.ResourceBundleMessageSource">

                        <property name="basename" value="messages"/>     

   </bean>    

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>app3</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

 

            <servlet>

                        <servlet-name>controller</servlet-name>

                        <servlet-class>

                                    org.springframework.web.servlet.DispatcherServlet

                        </servlet-class>

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

            </servlet>

            <servlet-mapping>

                        <servlet-name>controller</servlet-name>

                        <url-pattern>/</url-pattern>    

            </servlet-mapping> 

</web-app>