aspose file tools*
The moose likes Servlets and the fly likes getParameter with double quotes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getParameter with double quotes" Watch "getParameter with double quotes" New topic
Author

getParameter with double quotes

Jeff Hancock
Greenhorn

Joined: Nov 17, 2000
Posts: 11
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeff Hancock
Greenhorn

Joined: Nov 17, 2000
Posts: 11
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.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getParameter with double quotes