Implement jsp redirection webpage effects and jsp redirection webpage
Use the sendRedirect () method in the request object to redirect (webpage jump) to another page.
Format: request. sendRedirect ("*. jsp ");
And forwarding The difference: the former can jump to any address page, and the latter can only jump to this website. The former jumps with the information in the request, and the latter does not.
For example, you can enter the logon name and password on the logon page, and enter the correct and wrong passwords to go to different pages.
Code:
Login. jsp
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
Receive. jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<% String name = request. getParameter ("rdname"); String passwd = request. getParameter ("rdpasswd"); if (name. equals ("abcd") & passwd. equals ("123456") {%>
<%} Else {%> <% response. sendRedirect ("https://sohu.com");} %>
Correct. jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% String name = request. getParameter ("rdname"); %> welcome, <% = name %> login successful! Running result (correct ):
Running result (error ):