SunQuest
           Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old October 9th, 2002, 01:47 PM
dchin dchin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Rochester, NY
Posts: 0 dchin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 26 sec
Reputation Power: 0
Esacping in JSP?

I was able to do this in PHP, but I can't figure out how to escape a string in JSP... I am working on a a form for inputing data into an Oracle DB. I am using a <textarea> for a description field. In that past, I always escaped textarea's to avoid problems. How on earth do you accomplish this task in JSP?

Any help would be great,
Thanks in advance,
Dower

Reply With Quote
  #2  
Old October 9th, 2002, 03:41 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
What do you mean by escaping? Can you give an example?

Reply With Quote
  #3  
Old October 9th, 2002, 09:06 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
maybe a "magic_quotes" thing???

escaping ' characters, etc.

???

Reply With Quote
  #4  
Old October 9th, 2002, 09:48 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Ya, sounds like either quotes or entity replacement.

dchin, riddle me this: what version of the jdk are you using?

Reply With Quote
  #5  
Old October 10th, 2002, 09:18 AM
jfhiller jfhiller is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 1 jfhiller User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to jfhiller
Man, that same thing has given me fits in the past. I think you could use a servlet method to just replace any instance of ' or " with \' or \". Shouldn't be too difficult. You might use a StringTokenizer to break the string at those chars and then concatenate back together with the appropriate escaped characters in between. Not ideal, I know, but it would probably be effective without too much additional work.

Reply With Quote
  #6  
Old October 10th, 2002, 10:18 AM
dchin dchin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Rochester, NY
Posts: 0 dchin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 26 sec
Reputation Power: 0
Actually, I'm trying to take input from a text field to make it safe for database input. changing characters like % ' " or other characters that would screw up an SQL statement into \' \" or something similar. I used commands like addslashes for quotes in PHP, and I performed ereg replaces on others.

I recently found the URLEncode and URLDecode methods, and they seem to do the trick, I just wonder if there are better ways. Also, does anyone know how to do regular expressions?

Reply With Quote
  #7  
Old October 10th, 2002, 10:38 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
You have to have jdk 1.4 or later to do regex.

Reply With Quote
  #8  
Old October 10th, 2002, 07:43 PM
ghatzhat ghatzhat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 361 ghatzhat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 5 sec
Reputation Power: 7
If you use a PreparedStatement instead of just a Statement, then the database driver will take care of escaping single quotes and so on for you.

However, on MySQL, with the mm.mysql driver I have had difficulties with using the SQL % symbol (as the PreparedStatement escapes it). In these cases I used regex (Did that really only come along at 1.4? It's pretty fundamental!).
__________________
Little more than a playground for the bugs that live beneath us...

Reply With Quote
  #9  
Old October 22nd, 2002, 03:33 PM
dchin dchin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Rochester, NY
Posts: 0 dchin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 26 sec
Reputation Power: 0
Thumbs up Prepared Statement did it

Thanks for the help folks. ghatzhat's Prepared Statement option did the trick. I didn't need to manually convert the field data.

Dower

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Esacping in JSP?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway