Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

getParameter with double quotes

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a servlet that is using the request objects getParameter() method to retrieve a string. The string contains a double quote (") and is therefore truncated somewhere between the client and the servlet. Is there anyway to retrieve the value in it's entirety without truncating? the value is (3/16"):ABSBT. Am only getting (3/16
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This needs to be handled when the parameter is being posted, not when being retrieved. If the request parameter is posted as part of a form, all would be well. So I suspect that somewhere along the line the parameter is being tacked onto a URL "by hand".
When doing so, it is very important to make sure that the parameter value is url-encoded using java.net.URLEncoder.
hth,
bear
 
Jeff Hancock
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the quick response. Actually, the field is part of an HTML textbox. The getparameter just gets the value from the text box. If the user types in a double quote, it is too late to encode it isn't it.

It isn't being passed in as part of the query string. The method is post.
Thank you again.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need to build an escape object or replacement object in Javascript so the data is sent across the internet correctly. At the least you should alert the usert that an illegal character has been found in the textbox & then simply remove it for them. A " is a terminator for data when being transfered so,yes , you will loose anything after that
 
Bear Bibeault
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the value is being posted via a form it is certainly being sent across correctly unless there's a serious bug in your web server. A quote character is most certainly not an illegal character and a user is free to enter it into a text field.
Are you sure that the call to getParameter() is returning the truncated value, or is it being lost upon display? For example, if your HTML is ending up like the following:

the browser will not render the field with the full value.
if that's the case, you should encode the string upon display.
hth,
bear
[ January 10, 2003: Message edited by: Bear Bibeault ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic