加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

JSP的request对象例子讲解

发布时间:2023-06-12 13:37:16 所属栏目:教程 来源:
导读:request通过可以获取客户端的数据和信息,当客户端向服务器发送请求时,web窗口将客户机的数据和信息存储到requeust对象中,下面错新技术频道小编就简单为大家介绍JSP的request对象实例讲解吧!

一 request对象定
request通过可以获取客户端的数据和信息,当客户端向服务器发送请求时,web窗口将客户机的数据和信息存储到requeust对象中,下面错新技术频道小编就简单为大家介绍JSP的request对象实例讲解吧!
 
一 request对象定义
 
客户端的请求信息被封装在request对象中,通过它才能了解客户的需求,然后做出响应。它是HttpServletRequest类的实例。request对象具有请求域,即完成客户端的请求之前,该对象一直有效。
 
二 request对象方法
 
三 实例
 
<%@ page language="java" import="java.util.*" contentType="text/html; charset=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%>" rel="external nofollow" >    <title>My JSP 'index.jsp' starting page</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" rel="external nofollow" >    --> </head>  <body>  <h1>request内置对象</h1>  <%    request.setCharacterEncoding("utf-8"); //解决中文乱码问题,无法解决URL传递中文出现的乱码问题。    request.setAttribute("password", "123456");    %>    用户名:<%=request.getParameter("username") %><br>     爱好 :<%      if(request.getParameterValues("favorite")!=null)      {          String[] favorites = request.getParameterValues("favorite");          for(int i=0;i<favorites.length;i++)          {           out.println(favorites[i]+"  ");          }        }    %> <br>     密码:<%=request.getAttribute("password") %><br>     请求体的MIME类型:<%=request.getContentType() %><br>     协议类型及版本号: <%=request.getProtocol() %><br>     服务器主机名 :<%=request.getServerName() %><br>     服务器端口号:<%=request.getServerPort() %><BR>     请求文件的长度 :<%=request.getContentLength() %><BR>     请求客户端的IP地址:<%=request.getRemoteAddr() %><BR>     请求的真实路径:<%=request.getRealPath("request.jsp") %><br>     请求的上下文路径:<%=request.getContextPath() %><BR>              </body></html>

四小知识点
 
1、解决URL传递中文参数乱码问题
 
修改D:/apache-tomcat-7.0.81/conf中的server.xml  <Connector port="8888" protocol="HTTP/1.1"  
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!