Escape Special Characters With Jakarta Commons

posted on 27 Jun 2005 21:50 by somkiat

สำหรับคนที่ต้องการหาวิธีการจัดการกับ Special Character เช่น <, >, &, .เป็นต้น

ใน Java นั้นมักจะมีปัญหากับตัว \ และ " (Double quote) ส่วนใน JavaScript จะมีปัญหากับ ' (Single quote) และสุดท้าย SQL ก็มักจะมีปัญหากับ single quote

โดยในการจัดการปัญหาเหล่านี้ก้มีหลายวิธีที่แตกต่างกันไป แล้วแต่จะคิดได้ครับ แต่วันนี้ผมขอแนะนำอีกวิธีครับ คือ Jakarta Common-Lang

จะใช้ class StringEscapeUtils ซึ่งจะใช้เป็นตัวช่วยสำหรับการจัดการอักษรพิเศษดังข้างต้น

จะมี 2 function หลักๆ ดังนี้

1. escapeHTML

2. unescapeHTML

ตัวอย่างการใช้งาน

String textWithBrackets = "There is always < (less) or > (more) than you want.";
String textEscaped = StringEscapeUtils.escapeHTML(textWithBrackets);
System.out.println(textEscaped); // There is always < (less) or > (more) than you want.
String textUnescaped = StringEscapeUtils.unescapeHTML(textEscaped);
System.out.println(textWithBrackets.equals(textEscaped)); // true

Resource

http://jakarta.apache.org/commons/lang/

Comment

Comment:

Tweet

chanel bags,http://www.chanelhandbags.net.in/softball bats,http://www.cheap-baseballbats.net/
nfl jerseys,http://www.cheapjerseys.us.org/
nfl jerseys,http://www.cheap-jerseys.us.org/
cheap jordan shoes,http://www.cheap-jordans.net/
michael kors,http://www.cheapmichaelkors.us.org/
nike shoes,http://www.cheap-nike-shoes.net/
oakley sunglasses,http://www.cheapoakley.us.org/
oakley sunglasses,http://www.cheapoakleysunglasses.ar.com/
oakley sunglasses,http://www.cheap-oakleysunglasses.in.net/
ray ban sunglasses,http://www.cheaprayban.com.co/
discount shoes,http://www.cheapshoes.com.co/
uggs outlet,http://www.cheap-uggboots.in.net/
dre beats,http://www.beatsbydrdre.co.com/
beats audio,http://www.beatsbydre.com.co/
beats audio,http://www.beats-by-dre.com.co/
beats audio,http://www.beats-headphone.in.net/
bebe clothing,http://www.bebeclothing.net/
bottega veneta,http://www.bottega.us/
burberry,http://www.burberrycanada.ca/
burberry outlet,http://www.burberry-handbags.us.org/
burberry outlet online,http://www.burberryoutlet.club/
burberry outlet online,http://www.burberryoutlet.me.uk/
burberry outlet,http://www.burberryoutletonline.ar.com/
burberry outlet online,http://www.burberrys-outlet.in.net/
burberry outlet,http://www.burberrys-outletonline.in.net/
calvin klein underwear,http://www.calvinklein.co.com/
celine bags,http://www.celinebags.org/
chanel sunglasses,http://www.chanel-bags.com.co/
polo ralph lauren,http://www.polo-outlets.com.co/
ralph lauren outlet,http://www.poloralphlaurenoutlet.net.co/
prada outlet,http://www.pradahandbags.com.co/
prada outlet,http://www.pradahandbags.net.co/
prada handbags,http://www.pradaoutlet.com.co/
prada outlet,http://www.pradashoes.com.co/
ralph lauren,http://www.ralph-lauren.ca/
ralph lauren,http://www.ralph-lauren.com.au/
ralph lauren uk,http://www.ralph-lauren.org.uk/
ralph lauren outlet,http://www.ralphlaurenepolo.com/
burberry,http://burberry.outletnow.org/
christian louboutin outlet,http://christianlouboutin.outlet-shoes.net/
tory burch sale,http://toryburch.salesandals.net/
abercrombie,http://www.abercrombie-and-fitch.ca/
abercrombie and fitch,http://www.abercrombieand-fitch.com.co/
abercrombie fitch,http://www.abercrombie-and-fitch.us.com/
abercrombie and fitch,http://www.abercrombiefitch.us.com/
abercrombie,http://www.abercrombie-kids.us.com/
adidas,http://www.adidas--canada.ca/
nike huarache,http://www.air-huarache.co.uk/
retro jordans,http://www.airjordans.us/
jordan release dates 2015,http://www.airjordanshoes2015.com/
air max 2014,http://www.airmax-2015.org/
air max,http://www.airmax-90.org/
babyliss pro,http://www.babyliss.us.org/
barbour jackets sale,http://www.barbour-factory.com/
barbour mens jackets,http://www.barbour-jacketsoutlet.com/
basketball shoes,http://www.basketballshoes.com.co/
bcbg max,http://www.bcbgdresses.net/
bcbg max,http://www.bcbg-max-azria.ca/
flat iron,http://www.chiflatiron.net.co/
louboutin,http://www.christian--louboutin.in.net/
louboutin shoes,http://www.christianlouboutin.org.uk/
louboutin outlet,http://www.christianlouboutinoutlet.net.co/
christian louboutin,http://www.christianlouboutinshoes.ar.com/
christian louboutin,http://www.christian-louboutin-shoes.ca/
louboutin shoes,http://www.christianlouboutinshoes.jp.net/
coach factory outlet online,http://www.coachfactory-outlet.co.com/
coach factory outlet,http://www.coachfactory-outlet-online.in.net/
coach purses,http://www.coach-handbags.com.co/
coach outlet,http://www.coachoutlet-online.com.co/
coach outlet,http://www.coachoutletstore.net.co/
coach outlet,http://www.coachoutletstore-online.com.co/
coco chanel,http://www.coco-chanelbags.com.co/
converse shoes,http://www.converse.net.co/
converse,http://www.converses-shoes.net/
handbags outlet,http://www.designerhandbagsoutlet.com.co/
ed hardy,http://www.edhardy.us.org/
glasses online,http://www.eyeglassesonline.us.org/
glasses frames,http://www.eyeglassframes.us.org/
boutique clothing,http://www.fashion-clothing.us.org/
salvatore ferragamo,http://www.ferragamo.com.co/
ferragamo,http://www.ferragamoshoes.net/
straightener,http://www.ghdhairstraightener.com.co/
giuseppe zanotti,http://www.giuseppezanotti.com.co/
gucci handbags,http://www.guccihandbags.net.co/
gucci outlet,http://www.gucci-outlet.biz/
gucci sale,http://www.gucci-outletsale.in.net/
gucci outlet,http://www.guccishoes.com.co/
gucci outlet,http://www.guccishoes.in.net/
gucci outlet,http://www.guccishoes.us.org/
gucci,http://www.gucci-uk.me.uk/
purses and handbags,http://www.handbagsoutlet.com.co/
harrods,http://www.harrods-london.co.uk/
katespade,http://www.kate-spade.net.co/
kate spade,http://www.katespade-outlet.net.co/
levi's jeans,http://www.levisjeans.com.co/
longchamp outlet,http://www.longchamp.com.co/
longchamp handbags,http://www.longchamp.us.org/
longchamp,http://www.longchamp-handbags.us.com/
longchamp,http://www.longchampoutlet.com.co/
christian louboutin,http://www.louboutin.jp.net/
louis vuitton,http://www.louisvuitton.jp.net/
louis vuitton,http://www.louis--vuitton.org.uk/
louis vuitton outlet,http://www.louisvuitton.so/
louis vuitton outlet,http://www.louisvuittonas.com/
louis vuitton,http://www.louis-vuitton-australia.com.au/
louis vuitton outlet,http://www.louis-vuittonblackfriday.com/
louis vuitton,http://www.louisvuitton-outlet.com.co/
louis vuitton,http://www.louis-vuittonoutletcanada.ca/
louis vuitton outlet,http://www.louisvuitton-outlets.us/
louis vuitton outlet,http://www.louisvuittonsas.com/
lululemon,http://www.lululemon-australia.com.au/
lululemon canada,http://www.lululemoncanada.ca/
lululemon,http://www.lululemonoutlet.com.co/
m a c cosmetics,http://www.maccosmetics.net.co/
marc jacobs handbags,http://www.marcjacobsonsale.com/
mcm handbags,http://www.mcm-bags.in.net/