request对象
2016-01-03 17:59
543 查看
request对象:
主要用于接收客户端发送而来的请求信息,客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。
通过getParmeter方法获得属性内容:
:<%@page contentType="text/html" pageEncoding="GBK" %>
<html>
<%
request.setCharacterEncoding("GBK");
String name=request.getParameter("name");
String password=request.getParameter("password");
%>
<body>
<h3>姓名:<%=name%></h3>
<h3>密码:<%=password%></h3>
</body>
</html>
如果按照最古老的方法获得表单的内容就是所有的参数使用getParmeter()接受,
而所有的数组则使用getParmeterValues()接受,但是现在可以换用一种新的方式
getPameterNames()接受
代码用例:
<%@page contentType="text/html" pageEncoding="GBK" %>
<html>
<body>
<form action="day2.jsp" method="post">
姓名:<input type="text" name="uname"><br>
性别:<input type="radio" name="sex" value="男" CHECKED>
男
<input type="radio" name="sex" value="女">女<br>
城市: <select name="city">
<option value="北京">北京</option>
<option value="天晶">天晶</option>
</select><br>
爱好:<input type="checkbox" name="**inst" value="唱歌" >唱歌
<input type="checkbox" name="**inst" value="跳舞">跳舞
<input type="checkbox" name="**inst" value="读书">读书<br>
自我介绍:<textarea cols="30" rows="3" name="note">
</textarea><br>
<input type="hidden" name="uid" value="1"><!-- 隐藏域 -->
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>
day2.jsp代码:
<%@page contentType="text/html" pageEncoding="GBK"%>
<%@page import="java.util.*" %>
<html>
<body>
<%
request.setCharacterEncoding("GBK");
Enumeration en=request.getParameterNames();
%>
<table border="1">
<tr>
<td>名称</td>
<td>内容</td>
</tr>
<%
while(en.hasMoreElements()){
String parmName=(String)en.nextElement();
%>
<tr>
<td><%=parmName%></td>
<td>
<%
if(parmName.startsWith("**")){
String ParamValue[] =request.getParameterValues(parmName);
for(int i=0;i<ParamValue.length;i++){
%>
<%=ParamValue[i]%>
<%
}
}
else{
%>
<%=request.getParameter(parmName) %></td>
</tr>
<%
}
%>
<%
}
%>
</table>
</body>
</html>
主要用于接收客户端发送而来的请求信息,客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。
通过getParmeter方法获得属性内容:
:<%@page contentType="text/html" pageEncoding="GBK" %>
<html>
<%
request.setCharacterEncoding("GBK");
String name=request.getParameter("name");
String password=request.getParameter("password");
%>
<body>
<h3>姓名:<%=name%></h3>
<h3>密码:<%=password%></h3>
</body>
</html>
如果按照最古老的方法获得表单的内容就是所有的参数使用getParmeter()接受,
而所有的数组则使用getParmeterValues()接受,但是现在可以换用一种新的方式
getPameterNames()接受
代码用例:
<%@page contentType="text/html" pageEncoding="GBK" %>
<html>
<body>
<form action="day2.jsp" method="post">
姓名:<input type="text" name="uname"><br>
性别:<input type="radio" name="sex" value="男" CHECKED>
男
<input type="radio" name="sex" value="女">女<br>
城市: <select name="city">
<option value="北京">北京</option>
<option value="天晶">天晶</option>
</select><br>
爱好:<input type="checkbox" name="**inst" value="唱歌" >唱歌
<input type="checkbox" name="**inst" value="跳舞">跳舞
<input type="checkbox" name="**inst" value="读书">读书<br>
自我介绍:<textarea cols="30" rows="3" name="note">
</textarea><br>
<input type="hidden" name="uid" value="1"><!-- 隐藏域 -->
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>
day2.jsp代码:
<%@page contentType="text/html" pageEncoding="GBK"%>
<%@page import="java.util.*" %>
<html>
<body>
<%
request.setCharacterEncoding("GBK");
Enumeration en=request.getParameterNames();
%>
<table border="1">
<tr>
<td>名称</td>
<td>内容</td>
</tr>
<%
while(en.hasMoreElements()){
String parmName=(String)en.nextElement();
%>
<tr>
<td><%=parmName%></td>
<td>
<%
if(parmName.startsWith("**")){
String ParamValue[] =request.getParameterValues(parmName);
for(int i=0;i<ParamValue.length;i++){
%>
<%=ParamValue[i]%>
<%
}
}
else{
%>
<%=request.getParameter(parmName) %></td>
</tr>
<%
}
%>
<%
}
%>
</table>
</body>
</html>
相关文章推荐
- 解决 UITableViewCell的点击事件和手势的冲突问题
- 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
- HDFS2—SequenceFile(小文件的解决方案)
- Android 子线程更新 UI
- 167,Xcode 3D查看UI布局效果
- UI组件的呈现
- QUESTION 47 How many copies of the alert log are stored in the directory specified by the initializa
- UUID 获取设备的唯一标志
- UVA 11133 - Eigensequence DP
- iOS开发笔记--如何去掉UItableview header(footer)view黏性(sticky)
- EasyUI Tree节点拖动到指定容器
- ios uialertview
- ios uitableviewcell 的具体功能实现
- iOS之UITableView组头组尾视图/标题悬停
- [easyui]单例模式封装组件,提高性能,按需使用
- Android高性能加载大量图片系列课程2-在非UI线程中处理图片
- EASYUI DATAGRID 多列复选框CheckBox
- 30分钟 带你浅入requirejs源码
- requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
- iOS开发- reloadData无效 (子线程更新UI错误)