0

When I try to hit the below URL

     https://netbanking.hdfcbank.com

it changes to onloading of the login page

    https://netbanking.hdfcbank.com/netbanking/

I just want to know how does the URL changes on hit. Can someone explain me this concept using Servlets

user1879683
  • 95
  • 2
  • 3
  • 9

5 Answers5

2

There are many ways to redirect the page :

  1. You can specify the redirection rule in web.xml file. Refer this for your reference.

  2. You can redirect to specific page using jstl. Refer this for <c:redirect > tag

  3. You can redirect to some other page in servlet using response.sendRedirect("pathOfThePage");

Community
  • 1
  • 1
Vimal Bera
  • 10,346
  • 4
  • 25
  • 47
  • I often see query strings get appended to the URL. How does this happen. I haven not seen any query strings appended to the URL but the URL changes to very long URL with query string appended to it. How does this happen. We use JSF – user1879683 Oct 29 '13 at 06:27
  • Its just way of passing some value to the servlet or controller using GET request. Refer [this](http://www.tutorialspoint.com/jsp/jsp_form_processing.htm) tutorial for form processing. – Vimal Bera Oct 29 '13 at 06:29
0

This is done by URL redirect. For example, from a Servlet u can do the redirect using:

response.sendRedirect("location");

Here is the description of sendRedirect from the docs:

Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0

Check out this : http://docs.oracle.com/javaee/6/api/javax/servlet/RequestDispatcher.html. Simple yet powerful.

Ravi raj
  • 136
  • 1
  • 1
  • 7
0

Another way of redirecting is <jsp:forward page="forwardpage.jsp"></jsp:forward> from a jsp page you can redirect another jsp page using the above way you can also use response.sendRedirect("forwardpage");

SpringLearner
  • 13,738
  • 20
  • 78
  • 116
0

You can also use UrlRewriteFilter as below:

<rule>
   <from>^/some/olddir/(.*)$</from>
   <to type="redirect">/very/newdir/$1</to>
</rule>

<rule match-type="wildcard">
   <from>/blog/archive/**</from>
   <to type="redirect">/roller/history/$1</to>
</rule>

you can read more about it here

tokhi
  • 21,044
  • 23
  • 95
  • 105