• Post Reply Bookmark Topic Watch Topic
  • New Topic

how does servlet interpret parameter string ?  RSS feed

 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
couple of questions :

1) if I have a Form including a field called name. User enters "Silly & Big Jim", what will the URL be like ? I saw the URL includes some special char like %xxx stuff that replaces the white space and special character. Question is how does the url "automatically" convert them ? Does the programmer need to do something to convert it ? If it is not converted, will it work ?

2) when servlet is invoked, it gets this funny string, can it automatically decode those stuff into special char ? Does programmer needs to do anything on servlet code to "decode" those %22 stuff ? another interesting question is -- Why does the server think "%22" is a special char instead of just "%" followed by "22" ??
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's called URL-encoding. Look it up on the web for more information, there should be a Wikipedia article.

And no, the URL isn't the one which automatically does the encoding. It's the browser which does that when it generates the URL. If you're asking about an HTML form, then the only programmer who can do anything about causing the parameter to be correctly URL-encoded is the programmer who wrote the browser. Which they did.

And when the servlet is invoked, the servlet container software automatically does the decoding and passes the decoded version of the parameter to the servlet. The servlet doesn't have to do that work.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark I thomas wrote:couple of questions :
Why does the server think "%22" is a special char instead of just "%" followed by "22" ??



Thats because "%" itself is encoded to a %25 -- Try hitting a google search with %22 and observe the address bar -->
http://www.google.com/search?hl=en&q=%2522&aq=f&aqi=&aql=&oq=

 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:It's called URL-encoding. Look it up on the web for more information, there should be a Wikipedia article.

And no, the URL isn't the one which automatically does the encoding. It's the browser which does that when it generates the URL. If you're asking about an HTML form, then the only programmer who can do anything about causing the parameter to be correctly URL-encoded is the programmer who wrote the browser. Which they did.

And when the servlet is invoked, the servlet container software automatically does the decoding and passes the decoded version of the parameter to the servlet. The servlet doesn't have to do that work.


Thanks. But if browser automatically does the encoding, then why do people still need to use response.encodeURL("...") when they forward servlet or jsp ? Is this encodeURL doing the same thing of converting those special char ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServletResponse.encodeURL() is used to implement session tracking on systems not configured to allow cookies.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!