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

来源:互联网 发布:好看的av女友 知乎 编辑:程序博客网 时间:2024/06/05 00:46
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>


0 0
原创粉丝点击