wood burning stoves 2.0*
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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "special char and html" Watch "special char and html" New topic
Author

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

/myservlet?name="john&mark"

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
Marshal

Joined: Jan 10, 2002
Posts: 61216
    
  66

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

/myservlet?name="john&mark"


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
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.

Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: special char and html