The Artima Developer Community
Sponsored Link

Java Buzz Forum
Difference between URL-rewriting URL-encoding in Servlet JSP

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Difference between URL-rewriting URL-encoding in Servlet JSP Posted: Jan 19, 2012 8:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Difference between URL-rewriting URL-encoding in Servlet JSP
Feed Title: Javarevisited Blog
Feed URL: http://javarevisited.blogspot.com/feeds/posts/default?alt=rss
Feed Description: Blog on Java, Unix, Linux, FIX Protocol technology. I share my experience as tutorial, article, interview questions, programming, design etc.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Javarevisited Blog

Advertisement



URL-rewriting vs URL-encoding in Servlet JSP

Main difference between URL-rewriting and URL-encoding is that URL-rewriting is a technique to maintain user session if cookies are not enabled on client browser or browser doesn't support cookie while URL-encoding is a way to pass string to server containing special characters  by converting special characters like space into some other characters like + . people often confuse between URL encoding and URL rewriting because of there names which sounds quite similar for new guys but functionality wise they are totally different to each other, Also servlet encodeURL() method adds more confusion because its sounds like its used for URL Encoding but indeed used for URL Rewriting. This is also a very popular servlet and JSP interview questions , I have also shared some more questions on my posts 10 Servlet Interview questions answers and 10 JSP interview questions and answers for Java programmer.


Difference between URL Rewriting and URL Encoding in JSP Servlet

difference between URL-Rewriting and URL-Encoding in Java ServletYou often need to encode URL before sending it to server and need to rewrite URL with session id in order to maintain session where cookie is not present. here are some more differences between URL-rewriting and URL encoding in Servlet JSP

1) java.servlet.http.HttpServletResponse methods encodeURL(String url) and encodeRedirectURL(String URL) is used to encode SesssionID on URL to support URL-rewriting. don't confuse with name encodeURL() because it doesn't do URL encoding instead it embeds sessionID in url if necessary. logic to include sessionID is in method itself and it doesn't embed sessionID if browser supports cookies or session maintenance is not required. In order to implement a robust session tracking all URL from Servlet and JSP should have session id embedded on it.

In order to implement URL-rewriting in JSP you can use use JSTL core tag all URL passed to it will automatically be URL-rewriting if browser doesn't support cookies.

While java.net.URLEncoder.encode() and java.net.URLDecoder.decode()is used to perform URL Encoding and decoding which replace special character from String to another character. This method uses default encoding of system and also deprecated instead of this you can use java.net.URLEncoder.encode(String URL, String encoding) which allows you to specify encoding. as per W3C UTF-8 encoding should be used to encode URL in web application.

2) In URL rewriting session id is appended to URL and in case of URL-encoding special character replaced by another character.

That's all on difference between URL-rewriting and URL-encoding, let me know if you come across some more differences between these URL Encoding vs URL-rewriting in Servlet and JSP.

Some more Java post you may like

Read: Difference between URL-rewriting URL-encoding in Servlet JSP

Topic: OpenShift Express: Deploy a Java EE application (with AS7 support) Previous Topic   Next Topic Topic: Profile your applications with Java VisualVM

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use