Press "Enter" to skip to content

Create 301 redirect with Java Server Pages (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" );
 %>