Request内置对象的使用

概述:request对象主要用于接收客户端发送的请求信息,客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。封装了用户提交的信息。在注册界面使用的多

实例1:设定并且获取属性值

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>展示信息</title>
</head>
<body>
<%
//设置值
request.setAttribute("username", "小红");
request.setAttribute("pwd", "12345678");
%>
<!-- 取值 -->
用户名:<%=request.getAttribute("username")%><br>
密码 :<%=request.getAttribute("pwd")%> </body>
</html>

网站的简单注册,没有信息验证注册界面(html编写)

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册界面</title>
</head>
<body>
<form action="successlogin.jsp" method="post">//action代表跳转到哪个界面
<h1 align="center">欢迎来到注册页面</h1>
<table align="center" border="1">
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr> <tr>
<td>密码:</td>
<td><input type="password" name="pwd"></td>
</tr> <tr>
<td>性别:</td>
<td><input type="radio" value="男" name="gender"
checked="checked">男 <input type="radio" value="女"
name="gender">女</td>
</tr>
<tr>
<td>爱好:</td>
<td><input type="checkbox" value="钓鱼" name="hobbies"
checked="checked">钓鱼 <input type="checkbox" value="跑步"
name="hobbies">跑步 <input type="checkbox" value="喝茶"
name="hobbies">喝茶 <input type="checkbox" value="看书"
name="hobbies" checked="checked"> 看书</td>
</tr> <tr>
<td>学历:</td>
<td><select name="education">
<option value="小学">小学</option>
<option value="初中">初中</option>
<option value="高中">高中</option>
<option value="大学">大学</option>
</select></td>
</tr>
<tr>
<td>备注:</td>
<td><textarea name="remark" rows="3" cols="13"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><button type="submit">注册</button>
<button type="reset">重置</button></td>
</tr>
</table> </form> </body>
</html>

跳转到成功界面显示信息

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>信息展示</title>
</head>
<body>
<h1>注册成功</h1>
<%
request.setCharacterEncoding("utf-8");//如果不设置提交编码的形式,会出现乱码。
//获取参数
String username=request.getParameter("username");
String pwd=request.getParameter("pwd");
String gender=request.getParameter("gender");
String remark=request.getParameter("remark");
String education=request.getParameter("education");
String [] hobbies=request.getParameterValues("hobbies");//将信息保存在数组中
%>
用户名:<%=username %><br>
密码:<%=pwd %><br>
性别:<%=gender %><br>
<%
out.print("爱好:");
for(int i=0;i<hobbies.length;i++){
out.print(hobbies[i]+"&nbsp;");//循环输出兴趣 }
%><br>
学历:<%=education %><br>
备注:<%=remark %> </body>
</html>

输入/输出对象

out对象

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>向界面输出字符串</title>
</head>
<body>
<%
out.print("hello jsp");
out.print("</br>");
//</br>不能直接写在java代码框里
out.println("你好啊");//println代表换行符,由于浏览器的原因可能不会换行
%> 缓冲区大小:<%=out.getBufferSize()%></br>
缓冲区剩余大小:<%=out.getRemaining()%></br>
是否自动关机清除缓冲区:<%=out.isAutoFlush()%></br> </body>
</html>

最新文章

  1. 引用js或css后加?v= 版本号的用法
  2. Angularjs promise对象解析
  3. NOI 动态规划题集
  4. Tomcat7配置数据源
  5. js定时相关函数:
  6. HTML5中的DOMContentLoaded 和 touchmove
  7. tableview在第一次显示时会自动relodata
  8. python学习笔记8(表达式和语句)
  9. 武汉科技大学ACM:1008: 零起点学算法64——回型矩阵
  10. WCF+AJAX最佳实践
  11. td文字过长部分显示,鼠标移动显示全部内容
  12. 微信小程序教学第二章:小程序中级实战教程之预备篇 - 项目结构设计&#160;|基于最新版1.0开发者工具
  13. Spring Data(一)概念和仓库的定义
  14. 进入django
  15. CSAPP深入理解计算机系统(第二版)第三章家庭作业答案
  16. Nginx 教程(3):SSL 设置
  17. MySQL解压版的安装与配置
  18. 伪分布式&amp;&amp;完全分布式&amp;&amp;高可用(zookeeper)的配置文件内容
  19. Error creating bean with name &#39;sessionFactory&#39; defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable t
  20. 一款纯css3实现的动画按钮

热门文章

  1. 不止跑路,拯救误操作rm -rf /*的小伙儿
  2. 基于vue2.0原理-自己实现MVVM框架之computed计算属性
  3. 笃情开源:我和 Apache DolphinScheduler 社区的故事
  4. 高效简单的.Net数据库“访问+操作”技术
  5. 趋势科技 redirfs模块的一个小问题
  6. linux 3.10 一个扇区异常可能引发的hung
  7. 前端架构-分层而治,铁打的MV流水的C
  8. [NOI P模拟赛] 传统艺能(子序列自动机、矩阵乘法,线段树)
  9. 「学习笔记」单调队列优化dp
  10. 域名+端口号 访问minio服务问题