HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
When you need to move the document to a new location, you need to use JSP redirect.
The easiest way is to use the redirect response object sendRedirect () method. Signature of this method are as follows:
public void response.sendRedirect(String location) throws IOException
This method will state code and the new page location as a response back to the browser. You can also use setStatus () and setHeader () method to get the same effect:
/en/en String site = "https://w3resource.net/" ; response.setStatus(response.SC_MOVED_TEMPORARILY); response.setHeader("Location", site); /en/en
This example shows how a JSP page redirects:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*,java.util.*" %> <html> <html> <head> <title>页面重定向</title> </head> <body> <h1>页面重定向</h1> <% // 重定向到新地址 String site = new String("https://w3resource.net/"); response.setStatus(response.SC_MOVED_TEMPORARILY); response.setHeader("Location", site); %> </body> </html>
PageRedirecting code above is saved in a file, and then visit http: // localhost: 8080 / PageRedirect , it will take you to https://w3resource.net/ .