Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

special char and html

 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic