Javaweb request对象 , 以及一些操作
来源:互联网 发布:126邮箱smtp端口号 编辑:程序博客网 时间:2024/05/30 12:03
JSP request 对象 :
request中包含了HTTP 请求中的所有的细节
包含 : HTTP 请求头信息
系统信息
请求方式
请求参数(GET 和 POST方式的参数都是一样的)
请求转发
request中包含了HTTP 请求中的所有的细节
包含 : HTTP 请求头信息
系统信息
请求方式
请求参数(GET 和 POST方式的参数都是一样的)
请求转发
等
# GET 和 POST 数据的的获取
#请求转发时的属性的获取
<%@ page language="java" pageEncoding="UTF-8" ContentType="text/html;charset=utf-8" %><%-- 1. 获取请求参数 --%><% //获取表单的信息 String username = ""; String password = ""; if( null == request.getParameter("hidden") ){ username = request.getParameter("username"); password = request.getParameter("password");%><html> <head> <title></title> </head> <body> <fieldset> <legend>用户登录</legend> </fieldset> <form name="form1" action="" ,method="POST" > 用户名 : <input type="text" name="username"/> 密码: <input type="password" name="password"/> <input type="hidden" name="hidden" value="login"/> <input type="submit" value="登录"/> </form> </body><% }else{%><%=username%> 你好 ,登录成功;</html
#请求转发时的属性的获取 # 1.send_attribute操作<%@ page language="java" pageEncoding="UTF-8" ContentType="text/html;charset=utf-8" %><html> <head> <title></title> </head> <body><% request.setAttribute("attr1","这是属性1");%> <jsp:forward page="get_attribute.jsp"> </body></html> # 2 .get_attribute.jsp<%@ page language="java" pageEncoding="UTF-8" ContentType="text/html;charset=utf-8" %><html> <head> <title></title> </head> <body><% String attrValue = request.getAttribute("attr1","这是属性1");%> <%="attr1 : "+attrVAlue %> </body></html>
#获取Cookie里面数据 : cookie.getCookies() 返回是一个Cookie 对象的集合<%@ page language="java" pageEncoding="UTF-8" ContentType="text/html;charset=utf-8" %><html> <head> <title></title> </head> <body><% Cookies cookies[] = request.getCookies(); if(cookie !=null){ for(int i=0;i<cookies.length;++i){ String cookieName = cookies[i].getName(); String cookieValue = URLDecoder.decode(cookies[i].getValue);%><!--输出信息--><%=cookieName+" : "+cookieValue%><% } }%> </body></html>
#获取客户端的信息<%@ page language="java" pageEncoding="UTF-8" ContentType="text/html;charset=utf-8" %><html> <head> <title></title> </head> <body><% //获取请求的方式 String method = request.getMethod(); //获取协议信息 String protocol = request.getProtocol(); //获取请求字符串的地址 String URL = request.getRequestURL(); //获取请求字符串的地址 String URI = request.getRequestURI(); //获取当前文件的绝对路径 String realPath = request.getRealPath("index.jsp"); //获取客户端IP String ip = request.getRemoteAddr(); //获取主机名称 String host = request.getRemoteHost(); //获取服务器的名字 String serverName = request.getServerName(); //获取客户端请求的脚本的路径 String clientPath = request.getServerPath(); //获取服务器端口号 String port = request.getServerPort();%> <jsp:forward page="get_attribute.jsp"> </body></html>
# 根据 request.getLocale 获取的locale对象来 判断<%@ page language="java" pageEncoding="UTF-8" ContentType="text/html;charset=utf-8" %><html> <head> <title></title> </head> <body><% java.util.Locale locale = request.getLocale(); //显示中文 String str = ""; if(locale.equals(java.util.Local.CHINA)){ str = "这是我的web程序"; }//end if //显示英文 if(locale.equals(java.util.Local.US)){ str = "this is my web application"; }//end if%> <%=str%><jsp:forward page="get_attribute.jsp"> </body></html>
阅读全文
0 0
- Javaweb request对象 , 以及一些操作
- JavaWeb-Request对象
- javaWeb中的request对象
- javaweb中的request对象
- javaweb开发入门-request对象
- javaweb之response、request对象
- JavaWeb中的request对象和reponse对象
- JavaWeb之servlet的request对象
- JavaWeb九大内置对象之request
- request对象的一些方法总结,request对象,request
- javaweb开发学习jsp内置对象之request对象
- JavaWeb之Request对象和Response对象详解
- JavaWeb---request
- Structs2中的参数传递方式以及对Web对象(request,session,application)的操作
- 深入体验JavaWeb开发内幕——关于Request对象
- JavaWeb使用request对象获取请求参数值
- [基础] -- [request] -- Request对象的一些属性和方法
- struts2的一些疑问:获取request对象
- Java 序列化
- volatile关键字的含义和作用
- Cipher
- 一个用JS编写的随机抽取号码的小程序
- JDBC批量操作 不管什么都特别的慢
- Javaweb request对象 , 以及一些操作
- django相关资源
- 博客说明
- ubuntu下的若干问题 E: Sub-process returned an error code
- 成绩转换
- GetLastError()返回值列表
- java设计模式之创建模式(工厂模式,Builder,单例,原型)
- JavaScript---原型
- 最短路计数(spfa)