response objects using the of example

  • 2020-10-07 18:40:06
  • OfStack

1. Use the sendRedirect() method provided by the response object to redirect a web page to another page. The redirection operation supports address redirection to a different host, which is different from forwarding. In the client browser, the jump address is obtained and the request link is resend. The user can see the address after the jump from the browser's address bar. After the redirection operation, the attributes in request are all invalidated and a new request object is started.

The syntax for the sendRedirect() method is as follows:

response.sendRedirect(String psth);

Example: Create a new ES13en.jsp page and add the Java redirection statement to body


<%@ page language="java" contentType="text/html;charset="UTF-8" pageEncoding="UTF-8"%>
 
<html>
 
 <head>
 
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
 
  <title> Home page </title>
 
 </head>
 
 <body>
 
  <%response.sendRedirect("login.jsp");%>
 
 </body>
 
</html>

Create a new ES21en. jsp layout login screen


<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title> User login page </title>
 </head>
 <body>
  <form name="form1" method="post" action="">
 用户名:<input name="name" type="text" id="name" style="width:120px"><br>
  The secret   Code: <input name="pwd" type="password" id="pwd" style="width:120px"><br>
 <input type="submit" name="Submit" value=" submit ">
  </form>
 </body>
</html>

Related articles: