四、Model1模式 第二课(中)

 

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>


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dwt1220

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值