jsp原理:
项目目录:
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/dologin.jsp" method="post">
用户名:<input type="text" name="username" value="username"><br>
密码:<input type="password" name="userpassword" value="userpassword"><br/>
<input type="submit" name="submint" value="submit">
</form>
</body>
</html>
dologin代码:
<%@ 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>
<%
//获取表单数据
String username=request.getParameter("username");
String userpassowrd=request.getParameter("userpassword");
//处理业务逻辑
if("tom".equals(username)&&"123".equals(userpassowrd)){
request.getRequestDispatcher("/succes.jsp").forward(request, response);
}else{
response.sendRedirect("/jsp/login.jsp");
}
//分发转向
%>
</body>
</html>
succes.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>
欢迎你<%
String username=request.getParameter("username");
out.print(username);
%>
</body>
</html>
运行效果:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/94170.html