JSP引擎的内置对象Request对象来获取客户提交的信息
2017-11-30 21:25
302 查看
Example3_4.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Request对象</title>
</head>
<body>
<form action="tree2.jsp" method="post">
<input type="text" name="username" /> <input type="submit" value="提交"
name="submit" />
</form>
</body>
</html>
tree2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<br>
<span style="color: blue"> 客户使用的协议是: <%
String protocol = request.getProtocol();
out.println("<span style='color:red'>" + protocol + "</span>");
%>
</span>
<br>
<span style="color: blue">获取接收客户提交信息的页面: <%
String path = request.getServletPath();
out.println("<span style='color:red'>" + path + "</span>");
%></span>
<br>
<span style="color: blue">接收客户提交信息的长度: <%
int length = request.getContentLength();
out.println("<span style='color:red'>" + length + "</span>");
%></span>
<br>
<span style="color: blue">客户提交信息的方式: <%
String method = request.getMethod();
out.println("<span style='color:red'>" + method + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中user-agent的值: <%
String header1 = request.getHeader("User-Agent");
out.println("<span style='color:red'>" + header1 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中accept的值: <%
String header2 = request.getHeader("accept");
out.println("<span style='color:red'>" + header2 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中host的值: <%
String header3 = request.getHeader("Host");
out.println("<span style='color:red'>" + header3 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中accept-encoding的值: <%
String header4 = request.getHeader("accept-encoding");
out.println("<span style='color:red'>" + header4 + "</span>");
%></span>
<br>
<span style="color: blue">获取客户的IP地址: <%
String IP = request.getRemoteAddr();
out.println("<span style='color:red'>" + IP + "</span>");
%></span>
<br>
<span style="color: blue">获取客户机的名称: <%
String clientName = request.getRemoteHost();
out.println("<span style='color:red'>" + clientName + "</span>");
%></span>
<br>
<span style="color: blue">获取服务器的名称: <%
String serverName = request.getServerName();
out.println("<span style='color:red'>" + serverName + "</span>");
%></span>
<br>
<span style="color: blue">获取服务器的端口: <%
int serverPort = request.getServerPort();
out.println("<span style='color:red'>" + serverPort + "</span>");
%></span>
<br>
<span style="color: blue">获取客户端提交的所有参数的名字: <%
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String s = (String) e.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
<br>
<span style="color: blue">获取头名字的一个枚举: <%
Enumeration enum_headed = request.getHeaderNames();
while (enum_headed.hasMoreElements()) {
String s = (String) enum_headed.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
4000
;
<br>
<span style="color: blue">获取头文件中指定头名字的全部值的一个枚举: <%
Enumeration enum_headedValues = request.getHeaders("cookie");
while (enum_headedValues.hasMoreElements()) {
String s = (String) enum_headedValues.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
<br>
<span style="color: blue">按钮的名字: <%
String buttonName = request.getParameter("submit");
//以独特的字节编码格式读入到一个字节数组内存
//再将该字节数组转换成字符串
%></span>
<br><%=buttonName%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Request对象</title>
</head>
<body>
<form action="tree2.jsp" method="post">
<input type="text" name="username" /> <input type="submit" value="提交"
name="submit" />
</form>
</body>
</html>
tree2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<br>
<span style="color: blue"> 客户使用的协议是: <%
String protocol = request.getProtocol();
out.println("<span style='color:red'>" + protocol + "</span>");
%>
</span>
<br>
<span style="color: blue">获取接收客户提交信息的页面: <%
String path = request.getServletPath();
out.println("<span style='color:red'>" + path + "</span>");
%></span>
<br>
<span style="color: blue">接收客户提交信息的长度: <%
int length = request.getContentLength();
out.println("<span style='color:red'>" + length + "</span>");
%></span>
<br>
<span style="color: blue">客户提交信息的方式: <%
String method = request.getMethod();
out.println("<span style='color:red'>" + method + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中user-agent的值: <%
String header1 = request.getHeader("User-Agent");
out.println("<span style='color:red'>" + header1 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中accept的值: <%
String header2 = request.getHeader("accept");
out.println("<span style='color:red'>" + header2 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中host的值: <%
String header3 = request.getHeader("Host");
out.println("<span style='color:red'>" + header3 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中accept-encoding的值: <%
String header4 = request.getHeader("accept-encoding");
out.println("<span style='color:red'>" + header4 + "</span>");
%></span>
<br>
<span style="color: blue">获取客户的IP地址: <%
String IP = request.getRemoteAddr();
out.println("<span style='color:red'>" + IP + "</span>");
%></span>
<br>
<span style="color: blue">获取客户机的名称: <%
String clientName = request.getRemoteHost();
out.println("<span style='color:red'>" + clientName + "</span>");
%></span>
<br>
<span style="color: blue">获取服务器的名称: <%
String serverName = request.getServerName();
out.println("<span style='color:red'>" + serverName + "</span>");
%></span>
<br>
<span style="color: blue">获取服务器的端口: <%
int serverPort = request.getServerPort();
out.println("<span style='color:red'>" + serverPort + "</span>");
%></span>
<br>
<span style="color: blue">获取客户端提交的所有参数的名字: <%
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String s = (String) e.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
<br>
<span style="color: blue">获取头名字的一个枚举: <%
Enumeration enum_headed = request.getHeaderNames();
while (enum_headed.hasMoreElements()) {
String s = (String) enum_headed.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
4000
;
<br>
<span style="color: blue">获取头文件中指定头名字的全部值的一个枚举: <%
Enumeration enum_headedValues = request.getHeaders("cookie");
while (enum_headedValues.hasMoreElements()) {
String s = (String) enum_headedValues.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
<br>
<span style="color: blue">按钮的名字: <%
String buttonName = request.getParameter("submit");
//以独特的字节编码格式读入到一个字节数组内存
//再将该字节数组转换成字符串
%></span>
<br><%=buttonName%>
</body>
</html>
相关文章推荐
- JSP的内置对象--(使用request对象获取请求)
- jsp调用getParameter获取客户提交的信息
- struts2获取jsp内置对象和ValueStack对象方法
- JAVAWEB开发之Session的追踪创建和销毁、JSP详解(指令,标签,内置对象,动作即转发和包含)、JavaBean及内省技术以及EL表达式获取内容的使用
- 使用EL内置对象获取JSP内置对象的数据
- jsp-创建及获取客户的会话信息
- JSP内置对象---request对象
- jsp另外五大内置对象之response-设置头信息
- jsp内置对象之request对象
- JSP的内置对象-----request对象
- jsp内置对象【03】request对象详解【01】
- javaEE servlet获取jsp内置对象
- jsp中国文字形式提交,request对象获取乱码
- JSP内置对象之--request对象
- JSP内置对象--request对象 (setCharacterEncoding("GBK"),getParameter(),getParameterValues(),getParameterNames(),getServletPath(),getContextPath()
- JSP内置对象--request对象
- jsp exception对象获取异常信息
- jsp表单提交中文字符,request对象获取时乱码
- JAVA-JSP内置对象之session对象获得session的其他信息
- struts2 中jsp的9个内置对象、四种作用域、转发和重定向及在Action中获取session