Results 1 to 6 of 6

Thread: How to redirect a page in JSP

  1. #1
    Join Date
    Nov 2009
    Posts
    862

    How to redirect a page in JSP

    Hello, I am working on java programming language and while working on it, I want to know the details about How to redirect a page in JSP. I have tried to perform it, but it is not get solved by me, so if you are having any solution for it, then It will be helpful to me. So, please help me for that.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: How to redirect a page in JSP

    Hey, I have tried it as below. I have not tested it, so just compile and run it in your program:
    Code:
    boolean flag;
    System.out.println("Anything");
    flag=bean.Any();
    if(flag==false){
    %>
          <jsp:forward page="Impossible.jsp" />
    <%
    }

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to redirect a page in JSP

    If you want to redirect a JSP page then you need to simly call the response.sendRedirect() method in your scriptlet and you will able to get your problem solved. But it is necessary to call this method before the output gets flushed else you will get the exception. So, simply use the line of code below:
    Code:
    <% String redirectURL = "http://<sitename>/"; 
    response.sendRedirect(redirectURL); %>

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to redirect a page in JSP

    Syntax:
    Code:
    public void sendRedirect(java.lang.String location) throws java.io.IOException
    Description:
    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. If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to redirect a page in JSP

    Hello, redirecting in a jsp page is really a simple thing. You can achieve it with the help of below one:
    Code:
    if( condition() )
    {
    	res.sendRedirect( newlocation );
    	return;
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: How to redirect a page in JSP

    You can simply make use of the implicit object to redirect the jsp page to other page by the use of the response. For that you can use following line of code:
    Code:
    response.sendRedirect("<site name>");
    If you want to do the physical alteration of the location then you can simply make use of the code below:
    Code:
    <%
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    String location  = "newpath.html";
    response.setHeader("Location",location );
    %>

Similar Threads

  1. Websites redirect to solutioninc’s login page
    By RaAbi in forum Technology & Internet
    Replies: 3
    Last Post: 27-07-2011, 08:42 PM
  2. How to redirect page to print page in Google Chrome?
    By Sahira in forum Technology & Internet
    Replies: 5
    Last Post: 08-03-2010, 11:34 AM
  3. Not able to redirect to my home page
    By Flacos in forum Software Development
    Replies: 3
    Last Post: 10-11-2009, 08:22 PM
  4. Unable to redirect to login page
    By Rixwel in forum Windows Software
    Replies: 3
    Last Post: 07-08-2009, 01:27 PM
  5. How to Redirect From one page to another page in Asp.net
    By Jateen in forum Software Development
    Replies: 2
    Last Post: 15-01-2009, 08:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,044,987.88158 seconds with 17 queries