Model1的基础是JSP文件,它由一些相互独立的JSP文件,和其他一些Java.class组成(不是必须的)。这些JSP从HTTP Request中获得所需要的数据,处理业务逻辑,然后将结果通过response返回前端浏览器。
Model1有2类
1. 纯JSP技术,不然任何java.class
2. Jsp+java.class
缺点
1. 表现层和业务逻辑混在一起,乱
2. 在开发过程中,不利于多人的共同开发
3. 不利于后期的维护
有点
1. 简单,开发速度比较快
2. 比较适合开发小的项目
Login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body bgcolor="pink">
<center>
用户登录<br/>
<hr>
<form action="LoginCL.jsp">
用户名:<input type="text" name="username" /><br/>
<br/>
密 码:<input type="password" name="password" /><br/>
<input type="submit" value="登录" />
<input type="reset" value="清空" />
</form>
</center>
</body>
</html>
LoginCL.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'LoginCL.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
//接收用户名和密码,完成用户的验证
String username=request.getParameter("username");
String password=request.getParameter("password");
//验证,先不到数据库,就简单验证
if(username.equals("dwt1220")&&password.equals("123456")){
//跳转,Welcome.jsp
//如何讲LoginCL.jsp得到的数据传给下一个页面
//1.cookie 2.session 3.response.sendRedirect
response.sendRedirect("Welcome.jsp?username="+username+"&password="+password);
}else{
response.sendRedirect("Login.jsp");
}
%>
</body>
</html>
Welcome.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Welcome.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
欢迎登录. <br>
<%=request.getParameter("username") %>
<a href="Login.jsp">返回登录页面</a>
</body>
</html>