wood burning stoves
The moose likes HTML, CSS and JavaScript and the fly likes special char and html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "special char and html" Watch "special char and html" New topic

special char and html

mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
First posted in servlet ut thought it should be here.

1. Servlet takes a URL string and it include something like /myservlet?name="john". For server side, is it exactly same as passing

/myservlet?name=& quot ; john & quot ;


2. If this is fine. Then what if I have


How does server know it should take & quot ; as a unit, instead of interpreting it character by character ? What if I do have & as a char (like above) ??
How does it know this time it should only picks "&" without concatenating it with its adjacent chars ?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63352

Originally posted by mark I thomas:
First posted in servlet ut thought it should be here.

In the future please do not cross-post. Rather, have a moderator move the post if you post it in the wrong place.

/myservlet?name=& quot ; john & quot ;
That is not correct encoding. There is a big difference between HTML encoding and URL encoding.

Then what if I have


All parameter names and values on a URL need to be URL-encoded. On the server side investigate java.net.URLEncoder. On the client, the encodeURIComponent method can be used.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
The proper escape sequence for quote is %22 in the URL and not the HTML sequence that you posted.

You might want to play around with JavaScript's encodeURIComponent.

I agree. Here's the link: http://aspose.com/file-tools
subject: special char and html
It's not a secret anymore!