s2jsp第二章 jsp数据交互(一)

1.什么是内置对象?
内置对象就是由Web容器加载的一组类的实例,不需要使用“new”关键字获取实例
2.request的作用:
request对象主要用于处理客户端用户提交的请求信息。
3.response和request的异同: 
   response对象与request对象相对应,它用于响应客户请求并向客户端返回响应的信息
   response对象的sendRedircet()方法用于请求重定向到一个新的URL上
4.request内置对象的方法:
     getParameter(String name)  String类型
     getParameter(String name)  数组
     getRequestDispatcher(String path),该方法的forward()方法用于发送请求
Jsp的内置对象 request out response application page config session6
第一页:登录页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>注册页面</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>
  <form action="do.jsp" method="post">
     用户名:<input type="text" name="txtname" value="<%=request.getAttribute("name")%>"/>
    密码: <input type="password" name="txtpwd"/>
   
  <input type="submit" value="提交"/>
     </form>
  </body>
</html>
第二页:访问页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>处理页面</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>
   <%
         //    1.取出name属性  对应的value值
	     String name=request.getParameter("txtname");
	     //2.   取值 
	     String pwd=request.getParameter("txtpwd");
	     if(name.equals("sa")&&pwd.equals("sa")){
	     //作用域保存name
	     request.setAttribute("name", name);
	     //跳转操作
	     request.getRequestDispatcher("/index.jsp").forward(request,response);
     }else{
       request.setAttribute("name", name);
       request.getRequestDispatcher("/register.jsp").forward(request,response);
     }
      %>
  </body>
</html>

第三页:

<body>

 欢迎<%=request.getAttribute("name")
   %>
</body>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值