Java/JSP/Request — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:09, 1 июня 2010
Содержание
Get Request Parameter
HTTP Request Headers Received
<%--
Copyright (c) 2002 by Phil Hanna
All rights reserved.
You may study, use, modify, and distribute this
software for any purpose provided that this
copyright notice appears in all copies.
This software is provided without warranty
either expressed or implied.
--%>
<%@ page import="java.util.*" %>
<html>
<head>
<title>Echo</title>
<style>
<jsp:include page="style.css" flush="true"/>
</style>
</head>
<body>
<h1>HTTP Request Headers Received</h1>
<table border="1" cellpadding="4" cellspacing="0">
<%
Enumeration eNames = request.getHeaderNames();
while (eNames.hasMoreElements()) {
String name = (String) eNames.nextElement();
String value = normalize(request.getHeader(name));
%>
<tr><td><%= name %></td><td><%= value %></td></tr>
<%
}
%>
</table>
</body>
</html>
<%!
private String normalize(String value)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
sb.append(c);
if (c == ";")
sb.append("<br>");
}
return sb.toString();
}
%>
JSP Request Path
<%--
Copyright (c) 2002 by Phil Hanna
All rights reserved.
You may study, use, modify, and distribute this
software for any purpose provided that this
copyright notice appears in all copies.
This software is provided without warranty
either expressed or implied.
--%>
<pre>
In ShowPath2.jsp:
request.getRequestURI() = <%= request.getRequestURI() %>
request.getServletPath() = <%= request.getServletPath() %>
javax.servlet.include.request_uri =
<%= request.getAttribute
("javax.servlet.include.request_uri") %>
javax.servlet.include.servlet_path =
<%= request.getAttribute
("javax.servlet.include.servlet_path") %>
</pre>
JSP: Show Request
Request Parameters Example
<html>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<body bgcolor="white">
<h1> Request Information </h1>
<font size="4">
JSP Request Method: <% out.print(util.HTMLFilter.filter(request.getMethod())); %>
<br>
Request URI: <%= request.getRequestURI() %>
<br>
Request Protocol: <%= request.getProtocol() %>
<br>
Servlet path: <%= request.getServletPath() %>
<br>
Path info: <% out.print(util.HTMLFilter.filter(request.getPathInfo())); %>
<br>
Query string: <% out.print(util.HTMLFilter.filter(request.getQueryString())); %>
<br>
Content length: <%= request.getContentLength() %>
<br>
Content type: <% out.print(util.HTMLFilter.filter(request.getContentType())); %>
<br>
Server name: <%= request.getServerName() %>
<br>
Server port: <%= request.getServerPort() %>
<br>
Remote user: <%= request.getRemoteUser() %>
<br>
Remote address: <%= request.getRemoteAddr() %>
<br>
Remote host: <%= request.getRemoteHost() %>
<br>
Authorization scheme: <%= request.getAuthType() %>
<br>
Locale: <%= request.getLocale() %>
<hr>
The browser you are using is <% out.print(util.HTMLFilter.filter(request.getHeader("User-Agent"))); %>
<hr>
</font>
</body>
</html>