本系列博客汇总在这里:JSP 汇总


目录


JSP 动态标签

forward 动态标签

forward 标签的作用是请求转发!forward 标签的作用与 RequestDispatcher#forward() 方法相同。

示例:

JSP(15)_ JSP 动态标签_forward 动态标签_JSP 动态标签

JSP(15)_ JSP 动态标签_forward 动态标签_forward 动态标签_02

JSP(15)_ JSP 动态标签_forward 动态标签_html_03

JSP(15)_ JSP 动态标签_forward 动态标签_JSP 动态标签_04

源码提供:

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>

<body>

<form action="/jsp_demo5/login.jsp" method="post">
<input type="hidden" name="isSubmit" value="1">
用户名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br>
<input type="submit" value="登录"><br>
</form>

<%
String isSubmit = request.getParameter("isSubmit");
if("1".equals(isSubmit))
{
String username = request.getParameter("username");
String password = request.getParameter("password");
if("wyx".equals(username)&&"123".equals(password))
{
request.setAttribute("userInfo",username+" 你好,欢迎登录");
%>
<jsp:forward page="/success.jsp"></jsp:forward>
<%
}
else
{
%>
<jsp:forward page="/fail.jsp"></jsp:forward>
<%
}
}
%>

</body>

</html>

如有错误,欢迎指正!