Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2005, 12:15 AM
Authorized User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with data that consist of quotes

Hi,
I have retrieve the data/value from the database that consist of single or double quotes but unable to display to the textbox in jsp page. if the value does not consist of quotes, then it perform fine

How can I resolve the above
 
Old December 19th, 2005, 07:45 AM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I couldn't understand exact problem, but regarding the single quote I
have on function which replace the single quote. Try to use this one before puting the string into the text box.
it might be work.


import java.util.regex.*;

               public String validateString(String str) {
                  String value="";
                  try{
                    String REGEX = "\'";
                    String INPUT = str;
                    String REPLACE = "\'\'";

                    Pattern p = Pattern.compile(REGEX);
                    Matcher m = p.matcher(INPUT);
                    value = m.replaceAll(REPLACE);
                  }catch(Exception e){}
                  return value;

                }


 
Old December 23rd, 2005, 11:13 AM
Authorized User
 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you could've done all that in one line...

value = m.replaceAll("\'", "\'\'");

Well, that's not the solution i suggest. I
guess you basically want to escape certain
special characters. If i'm not wrong, you would
have the same problem with even < and > symbols.

try this:

value = URLEncoder.encode(str, "UTF-8");

You don't have to decode this unless you are using this
in a javascript function. If so, use the unescape() function
of javascript.

________
Adarsh






Similar Threads
Thread Thread Starter Forum Replies Last Post
double quotes in data - giving error in storage lawsoncobol Access VBA 2 August 21st, 2006 02:55 AM
displaying single quotes and double quotes ren_123 Classic ASP Databases 2 February 22nd, 2006 02:17 PM
Problem with single quotes ' mnoon Access 7 March 16th, 2005 03:44 PM
Quotes in SQL String Retrieving Access Data ritag Access VBA 5 November 17th, 2004 06:04 PM
Double Quotes and Single Quotes Problem phungleon Classic ASP Basics 7 May 27th, 2004 01:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.