Create 301 redirect with Java Server Pages (JSP)

May 29, 2009 by satz  
Filed under JSP

What is 301 error:

The file requested has been moved permanently to another location. The new location is defined as part of the following information sent by the server. This is useful when we need to avoid the danger of  broken links in the site. Instead of deleting the file, we can just redirect the browser to a new location by using 301 redirect codes in our web pages.

<%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″ pageEncoding=”ISO-8859-1″%>
<%
response.setStatus(301);
response.setHeader( “Location”, “http://www.movedlocation.com”);
response.setHeader( “Connection”, “close” );
%>

  • Leave a Comment

    Leave your sincere comments and feed backs below. It helps us to improve the quality and encourages us to do more.

Speak Your Mind

Tell us what you're thinking...
All the support requests shall be posted at forum.tutorials2learn.com