This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
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: 60783
    
  65

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
 
Don't get me started about those stupid light bulbs.
 
subject: special char and html
 
Similar Threads
one servlet container per server or per JVM?
welcome file for virtual/logical path
How to redirect from backing bean to servlet ?
Create a json object in javascript
question about servlet-mapping and auto redirecting URL