This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

how does servlet interpret parameter string ?

 
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" ??
 
Marshal
Posts: 24935
61
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.
 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • 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 ?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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.
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!