Saturday, January 1, 2011

ক্যালেন্ডার

ক্যালেন্ডার
______________ মেঘেঢাকা তারা
দেওয়াল কিংবা ক্যানভাস এখন স্মৃতি
পোস্টার কিংবা পেল্লাই ফোটো
দখল করেছে আমর জায়গা,
আমি ছোট হতে হতে এখন
টেবিলের কোনে কিংবা টিভির মাথায়
আর আধুনিকতার জোয়ারে আরও ছোট্ট
মোবাইল কিংবা তোমার ল্যাপটপে,
আমার বুকে শুধু অংকের অধ্যায়
গোল গোল দাগে ভরিয়ে দাও আমার বুক
তোমার সুখ দুঃখের দিনো লিপি দিনপঞ্জিকা-
কতো হাসি-কান্না-আনন্দ-উৎসবে
আমি তোমার দিনের সাথি, থাকি সারা বছর|

একটি বছর আগে ঠিক এই দিনটায়
কতো আনন্দে আতস বাজির রসনাই-এ
জানিয়ে ছিলে আমায় সাদর অভ্যর্থনা|
আজ শেষ লগ্নে আমি অযত্নে অবহেলিত
অস্তিত্ব হীনতায় আমার ঠিকানা এখন আস্থাকুড়ে,
সুখে দুঃখে ছিলাম তোমার চিরো সাথি হয়ে
ওসব ময়লাধরা পুরান মলিন স্মৃতি|
আজ অন্য কেউ এসেছে আমার জায়গায়
অভ্যর্থনার জোয়ারে ভেসে, থাকবে- আরও একটা বছর
নিয়ে আসুক তোমার জীবনে নতুন ছোঁয়া
নতুন বছরের নতুন শুভেচছা |

Wednesday, December 22, 2010

সমান্তরাল

সমান্তরাল
______________ মেঘেঢাকা তারা
চলি চলি পথযে চলি এরযে হয়না শেষ
কোথায় গেলে বলতে পার এটার অন্তদেশ,
আলোর মেলায় গ্রন্থকথা কবির মতামত
আমজনতার ঘণ্টী নেড়ে অচেনা পথিকবর,
ভুবন পারের নীলের ছটায় উজ্জ্বল দিকবিদিক
রাঙা পথের গল্পকথা পাবে ঠিক ঠিক,
নবীন যারা নবীন মতে বিভোর তারা মত্ত
ভাঙ্গছে বাধা গড়ছে হেথা সৃষ্টি জয়ের শর্ত,
দিকে দিকে উঠছে জেগে নীড়ের নিদ্রা ভেঙে
অঙ্গিকারের রুপরেখায় পেছনে ফেলে দন্দ,
কোলের শিশু, গাছের পাতা, ঘাসের শিশিরবিন্দু শিশিররেখা
টলটলিয়ে রামধনুরং সমান্তরাল জীবন খাতা ||

Tuesday, December 21, 2010

মনের দুধারে

মনের দুধারে
______________ মেঘেঢাকা তারা
মনের দুধারে
দুতাবাস জানায় রাত্রির নীরবতা
আলো আঁধারি খেলা – নিশ্চুপ পাতা
পাল তোলা তরী হারিয়েছে হাল
কলকলিয়ে ওঠা নীরবতা
মনের দুধারে |

মনের দুধারে
ঝলমলিয়ে ওঠা আলো হঠাৎ হারায়
নিকস কালো বিদ্যুত পার
থেমেযায় ঝরা পাটা উলট পুরাণ
অন্তরে সুঘ্রাণ মলিন
মনের দুধারে |

মনের দুধারে
তেপান্তরের মাঠ নকসি কাঁথা
হাঁটু ঘোলা জল হারায়ে পথিক
বিন্দু বিন্দু স্ফটিক খেলা করে
শ্যামলা গাঁয়ের মেয়ে কোলকাতা
মনের দুধারে |

Friday, October 22, 2010

Spring with in a Day Part-10

Steeps fpr Spring Web Application Transaction
-------------------------------------------------------------
 Copy the jar files those are supplied by the spring people to D:\sprlibs directory.
 Copy commons-dbcp-1.2.2.jar, commons-pool-1.3.jar, commons-collections-3.2.jar and ojdbc14.jar are to the same directory.
 Remove hibernate2.jar and spring-hibernate2.jar files instead of using the spring jar file supplied by eclipse people used by provided by spring people.
 Create table bacc(aid number(10) Primary key, balance number(10,2));
Insert into back values (1,10000);
Insert into back values (2,20000);
 MyEclipse IDE will able to generate the DAO class can used by spring application.
 For back table MyEclipse generates –
pack.Bacc (POJO class), back.hbm.xml (mapping file), pack.BaccDAO (DAO class).



Transaction Service Code –
---------------------------------------------
package pack;
public class FTManager {
private BaccDAO dao;
public void setDAO(BaccDAO dao) {
this.dao=dao;
}
public void trasferFunds(Long aidOne, Long aidTwo, double amt) throws Exception {
Bacc b1,b2;
b1=dao.findById(aidOne);
b2=dao.findById(aidTwo);
b1.setBalance(new Double(b1.getBalance().doubleValue()-amt));
b1.setBalance(new Double(b1.getBalance().doubleValue()+amt));
}
}

Provide Main application Classes -
---------------------------------------------
package pack;
public class TxManager {
public static void main (Sting [] args) throws Exception {
ApplicationContext sc = new ClassPathXmlApplicationContext (“applicationContext.xml”);
Object obj;
obj = sc.getBean(“fmt”);
FTManager ftm=(FTManager) obj;
ftm.transaferFunds(new Long(1),new Long(2),1000);
}
}

Provide the info about the Service classes in applicationContext.xml file -
------------------------------------------------------------------------------
< id="”txManager”" class="”org.springframework.orm.hibernate3.HibernateTransactionManager”">
< name="”sessionFactory”">
< local="”sfBean”">< /ref>
< /property>
< /bean>
< id="”baccDAO”" class="”pack.BaccDAO”">
< name="”sessionFactory”">
< local="”sfBean”">< /ref>
< /property>
< /bean>
< id="”ftmTarget”" class="”pack.FTManage”">
< name="”dao”">
< local="”baccDAO”">< /ref>
< /property>
< /bean>
< id="”fmt”" class="”org.springframework.transaction.intercepter.TransactionProxyFactoryBean”">
< name="”transactionManager”">
< local="”txManager”">< /ref>
< /property>
< name="”target”">
< local="”fmtTarget”">< /ref>
< /property>
< name="”transactionAttributes”">
<>
< key="”*”" value="”PROPAGATION_REQUIRES_NEW,">
< /entry>
< /map>
< /property>
< /bean>

o Here ‘*’ represents all the methods.
o The Transaction Manager will start the new transaction before executing the business method.
o Transaction Manager roleback the transaction when exception will be thrown by the business method.

Note:
For configuring multiple business service classes we can use the configuration info provided in documentation of TransactionProxyFactoryBean.


As part of a spring based application we can provide the code to manage the transaction but this is not a recommended approach. We can use declarative transaction management by providing/ declaring the info about how the transaction has to be managed using transactionAttributes.
By default spring will roleback the transaction if an exception of type java.lang.Exception of its subclasses is thrown.
If we provided +java.lang.Exception as part of transactionAttributes the transaction will be committed when the exception will be thrown.

< key="”bmOne”" value="”PROPAGATION_REUIRED_NEW,">< /entry>

o PROPAGATION_REUIRED_NEW
o PROPAGATION_REUIRED (default)
o PROPAGATION_MANDATORY
o PROPAGATION_SUPPORTED
o PROPAGATION_NOT_SUPPORTED
o PROPAGATION_NEVER


• PROPAGATION_REUIRED_NEW
-----------------------------------
Spring will start a new transaction before executing the method. The transaction will be started even if there is an transaction.




• PROPAGATION_REUIRED
-----------------------------------
If we use PROPAGATION_REQUIRED spring will start a new transaction if there is no transaction. If there is a transaction, if we use PROPAGATION_REQUIRED then the method will be executed as part of existing transaction.

• PROPAGATION_MANDATORY
-----------------------------------
If there is no transaction then it is considered to be illegal. If there is a transaction then method will be executed as part of the existing transaction.

• PROPAGATION_SUPPORTED
-----------------------------------
If there is no transaction then method will be executed without transaction. If there is a transaction method will be executed as part of existing transaction.

• PROPAGATION_NOT_SUPPORTED
-----------------------------------
If there is no transaction then method will be executed without transaction. If there is a transaction method will be executed without transaction.

• PROPAGATION_NEVER
-----------------------------------
If there is no transaction then method will be executed without transaction. If there is a transaction will be not executed and this is considered to be illegal.

Note:
It is recommended to use the above three values when we want to perform the DB operation from a business method.

Spring with in a Day Part-9

Aspect Oriented Programming (AOP) –
-----------------------------------------------
AOP stands for Aspect Oriented Programming. It simplifies the development of Application.




Provide the Service class –
------------------------------------------
package pack;
public interface IBusSrv {
int bmone (int I, int j);
float bmtwo (float f1, float f2);
}
package pack;
public class BSImpl implements IBusSrv {
public int bmone (int i, int j) {
System.out.println(“-----bmone()------“);
Return i+j;
}
public float nmtwo (float f1, float f2) {
System.out.println(“-------bmtwo()-------“);
return f1+f2;
}
}

package pack;
public class BusSrvCls {
public void bXxx(String s, int i) {
System.out.println(“--------bmXxx()---------“);
}
public void bmYyy() {
System.out.println(“----------bmYyy()------“);
}
}

Provide Aspect Classes –
-----------------------------------------
package pack;
import org.springframework.apo.MethodBeforeAdvice;
import org.springframework.apo.AfterReturningAdvice;
public class OurAspect implements MethodBeforeAdvice, AfterReturningAdvice {
public void before (Method met, Object[] args, Object target) throws Throwable {
System.out.println(“…….before…..”+met.getName());
System.out.println(“…….before…..”+args.length);
System.out.println(“…….before…..”+target.getClass());
}
public void afterReturning (Object rval, Method met, Object[] args, Object target)
throws Throwable {
System.out.println(“…….aR…..”+rval);
System.out.println(“…….aR…..”+met.getName());
System.out.println(“…….aR…..”+args.length);
System.out.println(“…….aR…..”+target.getClass());
}
}


Provide the info about the Service classes and Aspect classes in spring-servlet.xml file -
-----------------------------------------------------------------------------------
spring-servlet.xml file –
< bean name=”xxxTergate” class=”pack.BSImpl”>< /bean>
< bean name=”yyyTergate” class=”pack.BusSrvCls”>< /bean>
< bean name=”osBean” class=”pack.OurAspect”>< /bean>

< bean id=”xxx” class=”org.springframework.aop.framework.ProxyFactoryBean”>
< property name=”target”>
< ref bean=”xxxTarget”>< /ref>
< /property>
< property name=”interceptorNames”>
< list>
< value> osBean< /value>
< /list>
< /property>
< property name=”proxyInterfaces”>
< value> pack.IBusSrv < /value>
< /property>
< /bean>
< bean id=”yyy” class=”org.springframework.aop.framework.ProxyFactoryBean”>
< property name=”target”>
< ref bean=”yyyTarget”>< /ref>
< /property>
< property name=”interceptorNames”>
< list>
< value> osBean< /value>
< /list>
< /property>
< property name=”proxyTargetClass”>
< value> true< /value>
< /property>
< /bean>




When the application calls getBena(“xxx”) method of spring container object a proxy object will be return. This object contains the code that used our aspect or advice and the target object based on BSImpl object.




When bmone() method is invoked on the Proxy, it calls before() method, bmone() method on target object and finally it calls afterReturning() method. OurAspect acts as an intercepter.




When the application calls getBean(“yyy”) method of the spring container object, a proxy object will be return and this object takes care of using OurAspect and BusServCls object.

Provide Main application Classes –
-----------------------------------------------------
package pack;
public class AOPTestClass {
public static void main (Sting [] args) throws Exception {
ApplicationContext sc = new ClassPathXmlApplicationContext
(“applicationContext.xml”);
Object obj;
Obj = sc.getBean(“xxx”);
IBusSrv ibs = (IBusSrv) obj;
ibs.bmone(10,20);
ibs.bmtwo(10.01f, 20.02f);
obj = sc.getBean(“yyy”);
BusSrvCls bsc = (BusSrvCls) obj;
bsc.bmXxx(“aa”, 10);
bsc.bmYyy();
}
}

Crosscutting concern –
-------------------------------
The code to manage the transactions and the code to manage the security is required at multiple parts and hence these are called as Crosscutting concern.

Disadvantage of OOPs –
-------------------------------
OOPs allows us to reuse the code by creating subclasses and subclasses, but creating the sense the super classes does not make sense in some classes (creating a Person class as a sub class of Dog class, creating TransactionManager as subclass of SecurityMamager does not make sense)

AOP solves OOPs problem –
-------------------------------
Aspect Oriented Programming solves this problem. It allows us to reuse the code. An aspect is a crosscutting concern. Login, Security management, Transaction management are the good example of aspect.



Join-Point –
-------------------------------
Using an aspect is called as advising. The point at which the aspect is advice is called as join-point. Before calling a method and after calling a method are examples of joint-points.

The code of OurAdvice is used along with BSImpl and BusSrvCls that is we have reused the code of OurAspect in multiple classes. Spring supports the transaction management by using aspect oriented programming.

Spring with in a Day Part-8

Form Controller mechanism
----------------------------------------------
We can deal with the forms in our application are implementing the controller class as the subclasses of AbstructWizardFormController or SimpleFormController.

FromView –
------------------------
The server face generates the form to get input is called form view or the JSP that generates the input form is called as form view.

Success View –
------------------------
When the user provides the data in the above form, the application must store the data in the database and generates the output including that completed the operating successfully, the JSP that is responsible to generating the output is called as success view.

SimpleFormController
------------------------
The internal code of SimpleFormController assumes the browser has send the request for form if the request of type GET and it assumes the form is submitted if the request of type POST.

Procedure for using SimpleFormController –
--------------------------------------------------
Provide a form view -
------------------------------
JSP code (npform.jsp):-
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
< form method=”post” action=”sfh.html”>
Prod id: < input type=”text” name=”pid”>< /br>
< spring:bind path=”pcb.pid”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
Prod Name: < input type=”text” name=”pname”>< /br>
< spring:bind path=”pcb.pname”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
Price: < input type=”text” name=”price”>< /br>
< spring:bind path=”pcb.price”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
< input type=”submit” value=”Store”>< /br>
< /form>



Provide Success View –
--------------------------------------
JSP code (pds.jsp):-
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
Successfully Store the Product < br>
Prod Id = ${requestScope.peb.pid} < br>
Prod Name = ${requestScope.peb.pname} < br>
Prod Price = ${requestScope.peb.price} < br>

Provide the command bean class –
-------------------------------------------
package pack;
public class ProductCB {
int pid;
String pname;
float price;
//add setter and getter for all properties
}

Provide code for validation –
--------------------------------------------
//add validator code

Provide Code for Controller class –
---------------------------------------------
package pack;
public class PDSController extends SimpleFormController {
public PDSController () {
this.setCatchSecond(1);
this.setCommandName(“pcb”);
this.setCommandClass(ProductCB.class);
this.setFormView(“npform”);
this.setSuccessView(“pds”);
}
public void doSubmitAction(Object cmd) throws Exception {
ProductCB cb=(ProductCB) cmd;
System.out.println(“Prod id=”+cb.getPid());
}
}

The method doSubmitAction() will be executed only when the data provided by user is valid. If this method throws no exception then the successView will be executed.

Provide the info about the controller in spring-servlet.xml file -
-------------------------------------------------------------------------------
spring-servlet.xml file –
< bean name=”/sfh.htm” class=”pack.PDSController”>< /bean>

SimpleFormController activities when it deals with the form -
-------------------------------------------------------------------------------



Procedure for using AbstructWizardFormController – (Multi Form Handle)
---------------------------------------------------------------------------------
Provide the info about the controller in spring-servlet.xml file -
---------------------------------------------------------------------------------
spring-servlet.xml file –
< bean name=”/mfh.htm” class=”pack.MFController”>< /bean>

Provide the command bean class –
-----------------------------------------------------------
package pack;
public class UserRegCB {
String username;
Stirng pwdOne;
Stirng pwdTwo;
int age;
Stirng fatherName;
Stirng motherName;
Stirng address;
Stirng email;
Stirng contactNo;
//add setter and getter for all properties
}




Provide Code for Controller class –
-----------------------------------------------------------------
package pack;
public class MFController extends
AbstructWizardFormController {
public MFController () {
this.setCommandName(“urcb”);
this.setCommandClass(UserRegCB.class);
String pages[] = new String[3];
pages[0] = “frmz”;
pages[1] = “frmone”;
pages[2] = “frmtwo”;
this.setPages(pages);
}
protected void validatePage(Object cmd, Errors errors, int page) {
switch(page){
case 0: //call page zero validation
break;
case 1: //call page one validation
break;
case 2: //call page two validation
break;
}
}
protected ModelAndView processFinish(HttpServletRequest request,
HttpServletReqponse response, Object cmd, BindException be) {
UserRegCB cb=(UserRegCB) cmd;
//call business logic service class
ModelAndView mav = new ModelAndView();
mav.addAllObjects(be.getModel());
mav.setViewName(“ur”);
}
}

In the above application we are provided the business logic in the controller class. This is a recommended approach; we must provide a separate set of classes called as Business Service classes for the implementation of the business logic.

Provide a form view -
--------------------------------------
JSP code (frmz.jsp):-
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
< form method=”post” action=”mfh.html”>
< input type=”hidden” name=”_page0” value=”true”/>
< input type=”hidden” name=”_target1” value=”true” />
User Name: < input type=”text” name=”userName”>< /br>

< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
Password: < input type=”text” name=”pwdOne”>< /br>
< spring:bind path=”pcb.pwdOne”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
Retype Password: < input type=”text” name=”pwdTwo”>< /br>
< spring:bind path=”pcb.pwdTwo”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
< input type=”submit” value=”Next”>< /br>
< /form>

JSP code (frmone.jsp):-
------------------------------------------
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
< form method=”post” action=”mfh.html”>
< input type=”hidden” name=”_page1” value=”true”/>
< input type=”hidden” name=”_target2” value=”true” />
Age: < input type=”text” name=”age”>< /br>
< spring:bind path=”pcb.age”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
Father’s Name: < input type=”text” name=”fatherName”>< /br>
< /spring:bind path=”pcb.fatherName”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< .spring:bind>
Mother Name: < input type=”text” name=”motherName”>< /br>
< spring:bind path=”pcb.motherName”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
< input type=”submit” value=”Next”>< /br>
< /form>

JSP code (frmtwo.jsp):-
------------------------------------
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
< form method=”post” action=”mfh.html”>
< input type=”hidden” name=”_page2” value=”true”/>
< input type=”hidden” name=”_finish” value=”true” />
Address: < input type=”text” name=”address”>< /br>
< spring:bind path=”pcb.address”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
Email: < input type=”text” name=”email”>< /br>
< spring:bind path=”pcb.email”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
Contact Number: < input type=”text” name=”contactNo”>< /br>
< spring:bind path=”pcb.contactNo”>
< c:forEach var=”emsg” items=”${status.errorMessages}”>
< c:out value=”${emsg}”/>
< /c:forEach>
< /spring:bind>
< input type=”submit” value=”Register”>< /br>
< /form>

Provide Success View –
----------------------------------------
JSP code (ur.jsp):-
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
< % System.out.println(“--------ur.jsp--------“); %>
Successfully Register User < br>
User name = ${requestScope.urcb.userName} < br>
Age = ${requestScope.urcb.age} < br>
email = ${requestScope.urcb.email} < br>

The controller classes uses / depends upon the Servlet API and Spring API i.e. the controller classes can be used only as part of spring based web application. If we provide the business logic in the controller classes then we can’t reuse the business logic in the other application.

Spring with in a Day Part-7

Spring server side validation
------------------------------------------------------
Validation Rules:
• username is required and minimum length 5 characters.
• pwdOne an pwdTwo must be same.
• Age is required and must between 15 to 45

JSP code (urform.html):-
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
< form method=”post” action=”ru.html”>
Name: < input type=”text” name=”username”>< /br>
Password: < input type=”text” name=”pwdOne”>< /br>
Retype Password: < input type=”text” name=”pwdTwo”>< /br>
Email: < input type=”text” name=”email”>< /br>
Age: < input type=”text” name=”age”>< /br>
< input type=”submit” value=”Register”>< /br>
< /form>



Command Class –
package pack;
public class UserRegCB {
String username;
String pwdOne;
String pwdTwo;
String email;
int age;
//add setter and getter for all properties
}

Note:
------------
class cat {}
class Rat {}
public class TessApp {
public static void main (String [] args) throws Exception {
Class c1 = Class.forName(“Cat”);
Class C2 = Class.froName(“Rat”);
System.out.println(Cat.class.isAssignableFrom(c1); //true
System.out.println(Cat.class.isAssifnableFrom(c2); //false
}
}
 Cat.class.isAssignableFrom() returns TRUE if the class c1 contains the information about Cat class or the information about the sub-class of the Cat class.



To take care of validation we must provide a class implementing the Validator interface.
package pack;
public class URCBValidator implements Validater {
public Boolean supports(Class cls) {
return pack.UserRegCB.class.isAssignableFrom(cls);
}
public void validate (Object cmd, Errors errors) {
UserRegCB cb = (UserRegCB) cmd;
If(cb.getUserName() == null || cb.getUserName().trim().equsals(“”)){
errors.rejectValue(“username”,”user.req.err”,”User is required”);
} else If(cb.getUserName().lenght < 5){
errors.rejectValue(“username”,”user.len.err”,
”User name less than 5 characters”);
}
If(cb.getPwdOne() == null || cb.getPwdOne().trim().equsals(“”)){
errors.rejectValue(“pwdOne”,”pwdOne.req.err”,
”Password is required”);
} else If(cb.getPwdTwo() == null || cb.getPwdTwo().trim().equsals(“”)){
errors.rejectValue(“pwdTwo”,”pwdTwo.req.err”,
”Password is required”);
} else If(cb.getPwdOne().equals(ch.getPwdTwo())){
errors.rejectValue(“pwdTwo”,”pwdTwo.same.err”,
”Retyped password is not same with Password”);
}
If(cb.getAge() == null || cb.getAge().trim().equsals(“”)){
errors.rejectValue(“age”,”age.req.err”,”Age is required”);
} else If(cb.getAge().lenght < 15 || cb.getAge().lenght > 45){
errors.rejectValue(“age”,”age.len.err”,”Age is not between 15 to 45”);
}
}
}

 The method supports() and Validate() will be called by the spring code.
 The supports() is used to check whether the Validator object can take care of validating the data available in a specific command bean object.
 And validate() is used to check whether the data is valid or not.

package pack;
public class URController extends AbstructCommandController {
public URController() {
this.setCommandName(“urcb”);
this.setCommandClass(UserRegCB.class);
this.setValidator(new URCBValidator());
}
protected ModelAndView handle (HttpServletRequest reuest,
HttpServletResponse response, Object cmd, BindException be)
throws Exception {
UserRegCB cb=(UserRegCB) cmd;
Map map = be.getModel();
ModelAndView mav=new ModelAndView();
mav.setViewName(“dispRes”);
mav.addAllObjects(map);
return mav;
}
}

spring-servlet.xml file –
< bean name=”/ru.htm” class=”pack.URController”>< /bean>

JSP code (dispReg.jsp):-
< %@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core” %>
< %@ taglib prefix=”spring” uri=”http://www.springframework.org/tags” %>
< %@ page isELIgnored=”true” %>
< c:out value=”${requestScope.urcb.userName}”/>
< spring:bind path=”urcb.userName”>
< c:forEach var=”emsg” item=”${status.errorMessages}”>
< c:out value=”${emsg}” />< /br>
< /c:forEach>
< /spring:bind>