When performing the <jsp: forward page = "relative path">: the </ jsp forward>, immediately end the current page displayed, jump to another page (JSP, HTML, Servlet class).
1, forward the label without parameters:
Jsp page is defined:
<% @ Page contentType = " text / HTML; charset = UTF-8 " Language = " the Java " %> <HTML> <head> <title> JSP learning </ title> </ head> <body> Today is National Day the next day holiday. <JSP: Forward Page = " forward.jsp " > </ JSP: Forward> Today is the second day of the National Day holiday. </ body> </ HTML>.
To jump to the definition of jsp page:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>forward</title> </head> <body> <h3>我是forward跳转后的页面!</h3> </body> </html>
After the jump address access has not changed, and forwarded a similar request.
Precautions:
Tags: <jsp: forward page = "relative path"> </ jsp: forward> intervening spaces.
2, forward the label tape parameters:
Setting forward tag values and keys:
<%@ page contentType="text/html;charset=utf-8" language="java" %> <html> <head> <title>jsp的学习</title> </head> <body> <jsp:forward page="forward.jsp"><jsp:param name="1" value="123"></jsp:param></jsp:forward> </body> </html>.
Gets the value of the keys:
<HTML> <head> <title> forward </ title> </ head> <body> <h3> and I am the forward jump page! </ H3> <H2> index.jsp to values obtained from: <% = request.getParameter ( " . 1 " )%> </ H2> </ body> </ HTML>
3, forward the application label in the login screen:
log.jsp achieve the collection of user information:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body bgcolor="aqua"> <center> <h3>登录</h3> <form method="get" action="check.jsp"> 用户名:<input type="text" name="username" size="12"><br> 密 码 :<input type="password" name="password" size="6" ><br><br> <input type="reset" value="取消"> <input type="submit" value="登录"> </form> </center> </body> </html>
check.jsp to verify the information submitted by the user:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>check</title>
</head>
<body>
<%
String name=request.getParameter("username");
String password=request.getParameter("password");
if(name.equals("zhai")&&password.equals("1997")){
%>
<jsp:forward page="success.jsp">
<jsp:param name="username" value="<%=name%>"></jsp:param>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="log.jsp"></jsp:forward>
<%
}
%>
</body>
</html>
This implements jsp acquires user information from log.jsp, and the information is encapsulated in the Forward, the page after the jump, the respective values can be obtained through the key.
success.jsp: implement information after a successful login display, access to the information forward Inside:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>success</title> </head> <body> <h3>登录成功,欢迎你:<%=request.getParameter("username")%></h3> </body> </html>