Struts 2 Integer Validation Example


integer validation example struts 2, struts 2 integer validation, number validating struts 2, regular expression validation struts 2, struts 2 validator

The validator type "int" in struts 2 is a range validator. It does not validate if the input is a valid integer. Therefore we would require to use regular expression to validate the integer. This example considers zip Code field which should be a valid integer.

This example uses AJAX for displaying the result on the same page. The contents of output.jsp are shown if the input validation passes.

MyAction.java
  
public class MyAction extends ActionSupport {

private String zipCode;

public String execute() throws Exception {

return SUCCESS;

}

public String getZipCode() {

return zipCode;

}

public void setZipCode(String zipCode) {

this.zipCode=zipCode;

}
}


MyAction-validation.xml
  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">





zipCode

Zip code should be a valid number






input.jsp

  
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<s:head theme="ajax" />

<title>Integer Validation Test</title>

</head>

<body>

<s:actionerror />

<s:fielderror />

<s:div id="showResult" theme="ajax" loadingText="Loading..." />

<s:form id="myAction" action="myAction" method="post"

validate="true">

<s:textfield key="addressLine1" label="Address Line 1" labelposition="left" cssStyle="size: 15"></s:textfield>

<s:textfield key="addressLine2" label="Address Line 2" labelposition="left" cssStyle="size: 15"></s:textfield>

<s:textfield key="city" label="City" labelposition="left" cssStyle="size: 15"></s:textfield>

<s:textfield key="state" label="State" labelposition="left" cssStyle="size: 15"></s:textfield>

<s:textfield key="zipCode" label="Zip Code" labelposition="left" cssStyle="size: 15" required="true"></s:textfield>

<s:textfield key="country" label="Country" labelposition="left" cssStyle="size: 15"></s:textfield>

<s:submit theme="ajax" targets="showResult" />

</s:form>

</body>
</html>


output.jsp

  
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="s" uri="/struts-tags"%>



<html>

<head></head>

<body>

Valid Data Entered !!

</body>

</html>


struts.xml
  

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">



/output.jsp
/input.jsp




40 Post Comment

Expert said...

This saved me lot of time...regex is the best way to do this....

JS Expert said...

Struts 2 seems much different then strtus 1, looks like a real revamp happened for this framework.

Software Wikipedia said...

Struts 2 is actually a re-branding of Webwork framework which had similar but more powerful features then struts. Its good to these two great open source communities have decided to merge and come up with one better framework.

Anonymous said...

Thanks a lot.... hardly i found working example for regex.

Anonymous said...

Hello, Thanks a lot for your example.
I need some help. How to restrict special characters? How to allow numeric values only?

Dave said...

You can use the same regular expression as in this example as its allowing only digits. So everything other then digits will be blocked including alphabets.

Anonymous said...

Nice Example ....

You can also find similar example like it

http://www.aoiblog.com/struts2-integer-validation

Anonymous said...

nike free, kate spade outlet, prada handbags, coach factory outlet, oakley sunglasses, true religion, coach purses, oakley sunglasses, louboutin, michael kors outlet, ray ban, louis vuitton outlet online, jordan shoes, coach factory, longchamp outlet, ray ban sunglasses, louis vuitton handbags, coach outlet, nike shoes, true religion outlet, tiffany and co, michael kors outlet, true religion jeans, oakley sunglasses, gucci outlet, louboutin, chanel handbags, polo ralph lauren outlet, oakley sunglasses, ray ban sunglasses, toms shoes, oakley sunglasses, tory burch outlet, air max, coach outlet store, nike air max, polo ralph lauren, burberry outlet online, burberry outlet online

Anonymous said...

air max, nfl jerseys, nike free, marc jacobs, chi flat iron, air max, hogan, air jordan, nike free, mcm handbags, new balance shoes, ghd, mont blanc, louis vuitton, yoga pants, louis vuitton, bottega, karen millen, longchamp, juicy couture outlet, louboutin, abercrombie and fitch, rolex watches, nike air max, ralph lauren, reebok outlet, birkin bag, ralph lauren, nike air max, vans, lancel, north face outlet, insanity, supra shoes, lululemon, ferragamo shoes, beats by dre, timberland, hollister, converse shoes, mulberry

pae young said...

I do not know Adon know someone posing as he mens barbour jacket sale was such a person will not get knifed him furious. Oh, you're Arab East. cheap loosen the sale, went to cheap womens barbour jacket the front of the Arab East. sale wrist is released, cheap womens barbour jacket barbour clearance outlet Think of the Arab East, though not handsome, but also the cheap womens barbour jacket masculine macho, such as Mongolia cheap womens barbour jacket amnesty, are out cheap womens barbour jacket of the back layer of sweat.

Guo Guo said...

louis vuitton handbags
coach handbags
coach outlet online
polo ralph lauren outlet
salvatore ferragamo
oakley sunglasses
michael kors outlet online
true religion outlet
swarovski jewelry
oakley outlet
michael kors handbags
asics running shoes
air jordan 6
ray ban sunglasses online
celine outlet online
tory burch sandals
babyliss
burberry handbags
cheap mlb jerseys
ray ban sunglasses
beats studio
calvin klein outlet
timberland boots
ray ban outlet
louis vuitton
nhl jerseys
discount oakley sunglasses
cheap ray ban sunglasses
coach outlet store online
chanel outlet
puma sneakers
lebron shoes
air jordan gamma blue
rolex watches
michael kors outlet online
tods shoes
tiffany and co
tiffany and co
air force 1 shoes
iphone 6 cases

Wenhao Guo said...

herve leger
cheap jordans
kobe bryants shoes 2015
adidas shoes
ugg boots
oakley sunglasses
michael kors handbags
cheap oakley sunglasses
celine handbags
vans shoes
mbt shoes
air jordan shoes
lacoste polo shirts
new balance shoes
new england patriots jerseys
converse outlet
lacoste shoes
coach outlet store
miami heat jersey
babyliss hair dryer
oakley sunglasses
michael kors outlet online sale
ray ban sunglasses
swarovski uk
cheap snapbacks
longchamp outlet
cartier watches
coach outlet online
supra shoes
coach outlet
christian louboutin shoes
ferragamo belts
nike running shoes
louis vuitton outlet stores
ghd hair straighteners
mulberry outlet
dansko outlet
nhl jerseys wholesale
true religion outlet
tiffany jewelry
achang0716

Wei Chen said...

QF0716
moncler coats
prom dresses
cheap football shirts
hermes bags
nike free,nike free run,free running,free run,nike running
phil mcconkey jersey,odell beckham jr jersey,michael strahan jersey,chris snee jersey,larry donnell jersey,peyton hillis jersey,carl banks jersey,lawrence taylor jersey,phil mcconkey jersey,justin tuck jersey,michael boley jersey,chase blackburn jersey
swarovski uk
barcelona soccer jersey
cleveland cavaliers jersey
nike free
chelsea football shirts
camisetas futbol baratas
nike air max 2014
swarovski crystal
the north face clearance
kate spade outlet
manchester united football shirts
chanel handbags
chiefs jersey
arizona cardinals jerseys
monster beats
ysl outlet
stephen curry jersey
nike trainers uk
football shirts

Junda Xu said...

20150718 junda
polo ralph lauren
chanel online shop
coach factory outlet
soccer shoes
michael kors
louis vuitton sacs
nike blazer high
cheap snapbacks hats
tory burch outlet online
cheap jordans free shipping
tory burch handbags
louboutin
michael kors outlet
ed hardy clothing outlet
kate spade bags
replica watches for sale
michael kors outlet
burberry handbags
ralph lauren polo shirts
oakley sunglasses
michael kors handbags
pandora bracelets
ray ban outlet
michael kors purse
michael kors handbags
longchamp pliage pas cher
cheap oakleys
polo outlet
ed hardy uk
ray ban sunglasses
christian louboutin
pandora charms
cheap oakley sunglasses
mcm backpack
pandora charms
football jerseys
ed hardy clothing uk
soccer jerseys for sale
chanel bags
louis vuitton borse

Meiqing Xu said...

15910meiqing
instyler curling iron
abercrombie fitch,abercrombie and kent,abercrombie & fitch,abercrombie outlet,abercrombie kids
toms outlet
ralph lauren uk
air jordan 11
ghd straighteners
louis vuitton handbags
michael kors uk
oakley outlet
nike huarache
air force 1
celine outlet
ray ban glasses
uggs on sale
nike roshe run
ray ban sunglass
louis vuitton
louis vuitton handbags
mont blanc pens
michael kors outlet
adidas superstar
coach outlet
louis vuitton
oakley sunglasses cheap
ray ban glasses
oakley sunglasses
air jordans
louis vuitton handbags
jeremy scott shoes
louis vuitton handbags

Hyabe Ibbe said...

2supra for sale
hermes birkin bag
coach purses outlet
nike high heels
fitflop
ugg boots clearance
kobe shoes
north face clearance
jordan 12
north face outlet 70% off
coach outlet
jordan 11
polo shirts for women
michael kors sale
coach purse
canada goose jackets
air jordan 12
gucci outlet
mbt shoes clearance
hermes bags
coach outlet
canada goose clearance
kobe shoes
cheap jordans shoes
coach factory outlet
juicy couture
mont blanc legend
rolex watches
columbia outlet store
nike air jordan shoes
joes new balance outlet
jordan 6
polo outlet
coachoutlet.com
coach factory outlet
cheap nike shoes
lebron james shoes
fitflop outlet store usa
pink jordans
abercrombie kids
nike outlets
north face jackets clearance
nike sale
timberland boots
canada goose coats
vans outlet
20150925hxt

风骚达哥 said...

20151012 junda
http://elsaesser-valarino.com/livredor/
http://freeadvertisingzone.com/showthread.php?p=1977734
http://daily-painting.blogspot.de/2011/03/significance-of-moment.html
http://www.terror-play.de/index.php?site=news_comments&newsID=17&commentspage=1&sorttype=ASC
http://www.shindy.cc/bbs/boke.asp?Userid_1569.showtopic.3207.html
http://www.mavpabasket.com/phpBB2/viewtopic.php?p=82350
http://ferus.home.pl/tees/forum/viewtopic.php?f=25&t=51181
http://struts.fromdev.com/2008/08/how-can-you-set-devmode-to-dynamically.html
http://jasonmraz.nl/forum/viewtopic.php?f=28&p=59797
http://www.rise-inside.de/index.php?forum-showposts-40-p1

风骚达哥 said...

20151012 junda
michael kors outlet
ugg outlet store
Coach Factory Outlet Private Sale
michael kors handbags
Ugg Boots,Ugg Boots Outlet,Ugg Outlet,Cheap Uggs,Uggs On Sale,Ugg Boots Clearance,Uggs For Women
louis vuitton outlet
Louis Vuitton Bags On Sale
air max 95,nike golf,nike janoski,air max 1,nike canada,nike plus,nike shox,nike factory store
ugg boots
cheap uggs
Coach Factory Outlet Private Sale
ugg boots sale
coach outlet
Louboutin Red Bottoms Shoes Outlet
Christian Louis Vuitton Red Bottoms
Louis Vuitton Bags On Sale
Michael Kors Outlet Sale Clearance
Abercrombie & Fitch Factory Outlet
ugg boots australia
Lebron James Basketball Shoes Sale
coach factory outlet
michael kors bags
ugg boots sale
tory burch outlet
Gucci Outlet Online Sale
michael kors handbag
air max 90
Michael Kors Outlet Online Mall
timberland boots for women
coach outlet online

Minko Chen said...

north face outlet, http://www.northface-outlet.cc/
mcm backpack, http://www.mcm.in.net/
michael kors outlet online, http://www.michaelkors-outlets.us.com/
ugg outlet online, http://www.uggboots-outlet.co.uk/
michael kors wallet sale, http://www.michaelkorswallet.net/
swarovski crystal, http://www.swarovskicrystals.co.uk/
cowboys jerseys, http://www.dallascowboysjersey.us/
mbt shoes outlet, http://www.mbtshoesoutlet.us.com/
michael kors outlet, http://www.michaelkorsfactoryoutlets.in.net/
iphone 6 cases, http://www.iphonecase.name/
ralph lauren outlet, http://www.poloralphlauren.us.org/
oakley sunglasses wholesale, http://www.oakleysunglasseswholesale.in.net/
hollister shirts, http://www.hollistershirts.co.uk/
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
hermes outlet store, http://www.hermesoutletstore.us.com/
los angeles clippers jerseys, http://www.clippersjerseystore.com/
nike free run uk, http://www.nikefreerunning.org.uk/
colts jerseys, http://www.indianapoliscoltsjersey.us/
baltimore ravens jerseys, http://www.baltimoreravensjerseys.us/
hogan,hogan outlet,scarpe hogan,hogan sito ufficiale,hogan interactive
louis vuitton,borse louis vuitton,louis vuitton sito ufficiale,louis vuitton outlet
1013

ninest123 Ninest said...

ninest123 11.24
louboutin uk, nike outlet, louis vuitton handbags, michael kors outlet online, nike air max, ralph lauren polo, longchamp bags, replica watches, christian louboutin, uggs outlet, burberry factory outlet, tiffany jewelry, uggs on sale, louis vuitton outlet, michael kors handbags, burberry outlet, tory burch outlet, ray ban sunglasses, oakley sunglasses, louis vuitton outlet, longchamp outlet, oakley sunglasses, ray ban sunglasses, ray ban sunglasses, oakley sunglasses, gucci handbags, oakley sunglasses, cheap jordans, ralph lauren outlet, tiffany jewelry, louis vuitton, uggs outlet, replica watches, michael kors outlet, prada handbags, michael kors, prada outlet, uggs on sale, christian louboutin, nike air max, louis vuitton outlet online, louboutin shoes, uggs on sale, nike free, michael kors outlet online, michael kors outlet store, longchamp outlet, cheap oakley sunglasses

ninest123 Ninest said...

north face pas cher, ray ban uk, polo lacoste pas cher, nike air max, nike air max uk, vanessa bruno pas cher, nike roshe uk, nike roshe run pas cher, abercrombie and fitch UK, nike air force, michael kors, michael kors outlet online, polo ralph lauren uk, true religion outlet, lululemon outlet, new balance, timberland pas cher, louboutin pas cher, michael kors uk, nike tn pas cher, hogan sito ufficiale, hermes pas cher, nike blazer pas cher, nike free pas cher, vans pas cher, nike air max pas cher, ralph lauren pas cher, nike air max uk, abercrombie and fitch, lunette oakley pas cher, true religion outlet, true religion jeans, coach outlet, burberry pas cher, sac guess pas cher, converse, north face uk, nike trainers uk, nike free, true religion outlet, hollister uk, mulberry uk, coach outlet store online, coach purses, michael kors, lunette ray ban pas cher, longchamp pas cher, longchamp soldes, jordan pas cher

ninest123 Ninest said...

supra shoes, coach outlet, bottes ugg pas cher, moncler, converse shoes outlet, canada goose pas cher, canada goose uk, juicy couture outlet, juicy couture outlet, moncler pas cher, sac louis vuitton, links of london uk, swarovski jewelry, sac louis vuitton, ugg,uggs,uggs canada, toms shoes, canada goose jackets, karen millen uk, montre pas cher, lancel, canada goose, moncler, uggs outlet, michael kors outlet, moncler uk, ugg uk, barbour, thomas sabo uk, wedding dresses uk, ugg,ugg australia,ugg italia, canada goose outlet, doke & gabbana, barbour jackets uk, replica watches, ugg pas cher, louis vuitton uk, moncler outlet, pandora charms, swarovski uk, marc jacobs, louis vuitton, canada goose outlet, pandora jewelry, louis vuitton, canada goose jackets, moncler, pandora uk, moncler jackets, moncler, hollister, pandora jewelry, canada goose

ninest123 Ninest said...

abercrombie and fitch, nike roshe run, soccer shoes, oakley, wedding dresses, polo ralph lauren, nike air max, nike air max, vans scarpe, valentino shoes, vans outlet, herve leger, p90x workout, beats by dre, iphone 5s cases, soccer jerseys, hollister, ray ban, instyler ionic styler, iphone cases, bottega veneta, insanity workout, s6 cases, timberland boots, giuseppe zanotti, jimmy choo outlet, iphone 6s plus cases, iphone 6 cases, mcm handbags, converse, reebok outlet, babyliss pro, louboutin, lululemon outlet, chi flat iron, mont blanc, new balance shoes, iphone 6 plus cases, north face outlet, salvatore ferragamo, mac cosmetics, asics running shoes, ghd hair, north face outlet, hollister clothing, softball bats, nfl jerseys, hermes handbags, ipad cases, celine handbags, gucci, iphone 6s cases
ninest123 11.24

艾丰 said...

jianbin0319
mlb jerseys
mizuno running shoes
air jordan 4
michael kors handbags
celine outlet
michael kors uk
michael kors outlet clearance
michael kors sale
lacoste polo shirts
cheap jordans
cheap mlb jerseys
futbol baratas
prada shoes
coach outlet canada
christian louboutin online
tiffany outlet
oakley sunglasses
michael kors online
prada handbags
michael kors outlet
michael kors handbags
rolex watches
ray-ban sunglasses
nba jerseys
longchamp handbags
cheap jordans
fitflop clearance
coach outlet
louis vuitton handbags
soccer jerseys
juicy couture tracksuit
links of london

dipali sharma said...

In instance they have an interest in your items then they will straight acquire your services online. buy usa facebook likes cheap

柯云 said...

2016-04-01keyun
nike sb shoes
christian louboutin shoes
coach outlet
gucci handbags
coach outlet
cheap oakley sunglasses
kobe 9
basketball shoes
toms shoes
nike uk
ray bans
air jordan 8
hollister outlet
coach outlet
kevin durant 8
gucci outlet
cheap oakley sunglasses
mont blanc pens
ray ban sunglasses
coach outlet
coach factory outlet
louis vuitton outlet
louis vuitton outlet
coach factorty outlet
ray bans
coach factorty outlet
ray ban sunglasses outlet
louis vuitton handbags
louis vuitton outlet
mont blanc legend
ray ban outlet
celine handbags
louis vuitton purses
air max 90
kate spade outlet
fake watches
toms wedges
timberland outlet
kate spade handbags

Cran Jane said...

Coach Outlet North Face Jackets Oakley Sunglasses Toms Outlet North Face Outlet Nike Outlet Nike Hoodies Tory Burch Flats Marc Jacobs Handbags Jimmy Choo Shoes Jimmy Choos
Burberry Belt Tory Burch Boots Louis Vuitton Belt Ferragamo Belt Marc Jacobs Handbags Lululemon Outlet Christian Louboutin Shoes True Religion Outlet Tommy Hilfiger Outlet
Michael Kors Outlet Coach Outlet Red Bottoms Kevin Durant Shoes New Balance Outlet Adidas Outlet Coach Outlet Online Stephen Curry Jersey

Hua Cai said...

juicy couture tracksuit
michael kors outlet sale
michael kors handbags wholesale
rolex watches
michael kors uk outlet
ray ban sunglasses sale
tiffany outlet
fitflops sale clearance
michael kors handbags
true religion outlet
cazal outlet
michael kors factory outlet
herve leger outlet
tory burch outlet online
coach outlet store
louboutin pas cher
mcm outlet
ralph lauren shirts
hollister shirts
true religion outlet
michael kors handbags
coach outlet online
true religion jeans outlet
rolex watches outlet
true religion jeans
lacoste polo shirts
true religion jeans
coach handbags
nike air huarache
michael kors handbags clearance
michael kors outlet
true religion jeans
mbt shoes
ralph lauren outlet
soccer jerseys
20160602caihuali

Chenzhen 20160303chenzhen said...

true religion jeans
louis vuitton outlet
yeezy boost 750
nike blazer
valentino
coach factory outlet
nike air force black
armani exchange
cheap jordan shoes
birkenstock outlet
ray ban outlet store
coach factory outlet
mizuno running shoes
rolex daytona
longchamp outlet
adidas superstar white
rolex watches for sale
coach outlet store
louis vuitton outlet
michael kors outlet
hollister clothing store
true religion outlet
babyliss hair dryer
cartier
abercrombie & fitch
coach outlet online
the north face outlet
michael kors outlet
louis vuitton purse
longchamp uk
mont blanc pens outlet
fitflops shoes
coach outlet online
louis vuitton bags
timberland boots outlet
timberland uk
vans outlet store
adidas gazelle
louboutin pas cher
michael kors outlet online
chenzhen2016610

Outlet Wade said...

nike basketball shoes 2016
Cheap Nike Air Max
Nike Air Max
New jordans 2016
cheap jordan shoes
Nike Air Max 2016
nike free 5.0
Nike Outlet
cheap kd shoes
Cheap Jordans
jordan shoes
Nike free Run
Cheap Jordans for sale
Nike Store
kobe basketball shoes
jordans 2016
jordans for sale
cheap nike basketball shoes
new jordans
cheap mbt shoes
fitflop outlet
fitflop sandals
lebron james shoes 2016
fitflops sandals
fitflops on sale
mizuno wave
fitflops
fitflop sale
mizuno wave prophecy 3
mbt shoes for men
fitflops sale

Eric Yao said...

Skechers Go Walk Adidas Yeezy Boost Adidas Yeezy Adidas NMD Coach Outlet North Face Outlet Ralph Lauren Outlet Puma SneakersPolo Outlet
Under Armour Outlet Under Armour Hoodies Herve Leger MCM Belt Nike Air Max Louboutin Heels Jordan Retro 11 Converse Outlet Nike Roshe Run UGGS Outlet North Face Outlet
Adidas Originals Ray Ban Lebron James Shoes Sac Longchamp Air Max Pas Cher Chaussures Louboutin Keds Shoes Asics Shoes Coach Outlet Salomon Shoes True Religion Outlet
New Balance Outlet Skechers Outlet Nike Outlet Adidas Outlet Red Bottom Shoes New Jordans Air Max 90 Coach Factory Outlet North Face Jackets North Face Outlet

raybanoutlet001 said...

kobe shoes
michael kors handbags,michael kors handbags clearance,michael kors clearance
skechers shoes for women
kobe bryant shoes
tiffany online
michael kors handbags clearance
vera bradley outlet
michael kors handbags

192.168.1.1 said...

This was actually what i was looking for, and i am glad to came here! Thank you very much

Unknown said...

michael kors outlet
michael kors outlet
michael kors outlet store
fitflops outlet
fitflops sale
christian louboutin outlet
longchamp handbags
ray ban sunglasses
celine outlet
michael kors outlet clearance
chanyuan0927

Hua Cai said...

rolex watches for sale
ugg boots
bottega veneta outlet
louis vuitton pas cher
michael kors outlet online
ferragamo outlet
ralph lauren uk
longchamp handbags
rolex watches,rolex replica watches,replica rolex watches,replica watches
true religion jeans
20161203caihuali

John said...

ray bans
louis vuitton handbags
ed hardy store
burberry handbags
mlb jerseys
louis vuitton outlet online
north face jackets
ugg australia outlet
adidas nmd r1
adidas store
20161207yuanyuan

琐事 said...

dolce and gabbana outlet
michael kors outlet
salvatore ferragamo
michael kors handbags
colts jerseys
ed hardy
supra shoes sale
buffalo bills jerseys
pandora jewelry
michael kors handbags

Unknown said...

louis vuitton outlet
louis vuitton outlet clearance
louis vuitton outlet online
michael kors outlet clearance
christian louboutin
louis vuitton outlet
fitflops shoes
hollister clothing
ray ban sunglasses
coach outlet online coach factory outlet
chanyuan2017.01.14

linda paris said...

niche bali food

عرفان صادقي said...

بک لینک

بانک مقاله

دانلود آهنگ

تبادل لینک

ساخت وبلاگ

ابزاردهی

Post a Comment

Search Web......