本系列博客汇总在这里:JSP 汇总
目录
JSP 动态标签
forward 动态标签
forward 标签的作用是请求转发!forward 标签的作用与 RequestDispatcher#forward() 方法相同。
示例:
源码提供:
login.jsp
<%@ 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>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>
如有错误,欢迎指正!