HTML Tutorials |
|
XML Tutorials |
|
Browser Scripting |
|
Server Scripting |
|
.NET (dotnet) |
|
Multimedia |
|
Web Building |
|
Java Tutorials |
|
Programming Langauges |
|
Soft Skills |
|
Database Tutorials |
|
Operating System |
|
Software Testing |
|
SAP Module |
|
Networking Programming |
|
Microsoft Office |
|
Accounting |
|
|
Erzeugen der Server Response: HTTP Status Codes |
Wenn ein web server auf den Antrag von der Datenbanksuchroutine oder von anderem web client reagiert, besteht die Antwort gew�hnlich einer Statuslinie, einigen Warte�berschriften, einer Leerzeile und aus dem Dokument
|
Spezifizieren von Status Codes
|
Wie oben beschrieben, besteht die HTTP Wartestatuslinie der HTTP Version, einem Status Code und aus einer verbundenen Anzeige. Da die Anzeige direkt mit dem Status Code verbunden ist und die HTTP Version durch den Bediener festgestellt wird, mu� alles servlet tun ist, Status Code einzustellen. Die Weise zu tun, die durch die setStatus Methode des HttpServletResponse ist.
Die setStatus Methode nimmt das interne (der Status Code) da ein Argument, aber, anstatt, ausdr�ckliche Zahlen, es zu verwenden, ist zuverl�ssiger freier und, die Konstanten zu verwenden, die in HttpServletResponse definiert werden. Der Name von jedem, das konstant ist, wird von der Standard-HTTP 1.1 Anzeige f�r jedes abgeleitet, das mit einem Pr�fix von Sc konstant, ganz Versalien ist (f�r Status Code) und von R�umen, die zu den Unterstreichen ge�ndert werden. So da die Anzeige f�r 404 nicht gefunden wird, ist die gleichwertige Konstante im HttpServletResponse SC_NOT_FOUND dort sind zwei Ausnahmen jedoch. Aus etwas ungeradem Grund wird die Konstante f�r Code 302 von der HTTP 1.0 Anzeige, nicht die HTTP 1.1 Anzeige abgeleitet, und die Konstante f�r den Code 307 fehlt zusammen.
Den Status Code einzustellen nicht immer bedeutet, da� du nicht die R�ckkehr ein Dokument ben�tigst. Z.B. obgleich die meisten Bediener die kleine �Akte nicht gefundene� Anzeige f�r 404 Antworten erzeugen, konnten servlets diese Antwort besonders anfertigen w�nschen. Jedoch wenn du dies tust, mu�t du sicher sein, response.setStatus zu benennen, bevor Sie irgendeinen Inhalt �ber PrintWriter senden.
Obgleich die allgemeine Methode der Einstellung von Status Codes einfach zum Anruf response.setStatus (intern) ist, gibt es zwei allgemeine F�lle, in denen eine Abk�rzungmethode im HttpServletResponse zur Verf�gung gestellt wird. Die sendError Methode erzeugt die Antwort 404 zusammen mit einer kurzen Anzeige, die innerhalb eines HTML Dokumentes formatiert wird. Und die sendRedirect Methode erzeugt die Antwort 302 zusammen mit einer Position �berschrift, die das URL des neuen Dokumentes anzeigt.
|
HTTP 1.1 Status Codes und ihre Bedeutung
|
Das Folgen ist die Liste aller vorhandenen HTTP 1.1 Status Codes, zusammen mit ihrer verbundenen Anzeige und Deutung. Du solltest vorsichtig sein, wenn Sie Status Codes verwenden, die nur in HTTP 1.1 vorhanden sind, da viele Datenbanksuchroutinen noch nur HTTP 1.0 st�tzen. Wenn du die Status Codes verwendest, die zu HTTP 1.1 spezifisch sind, in den meisten F�llen w�nschst du entweder zu �berpr�fst ausdr�cklich die HTTP Version des Antrags (�ber die getProtocol Methode des HttpServletRequest) oder aufhebst sie f�r Situationen, als kein HTTP 1.0 Status Code zum Klienten irgendwie besonders sinnvoll sein w�rde.
|
Status Code
|
Associated Message
|
Meaning
|
100
|
Continue
|
Continue with partial request. (New in HTTP 1.1)
|
101
|
Switching Protocols
|
Server will comply with Upgrade header and change to
different protocol. (New in HTTP 1.1)
|
200
|
OK
|
Everything's fine; document follows for GET and
POST requests. This is the default for servlets; if you don't use
setStatus, you'll get this.
|
201
|
Created
|
Server created a document; the Location header
indicates its URL.
|
202
|
Accepted
|
Request is being acted upon, but processing is not completed.
|
203
|
Non-Authoritative Information
|
Document is being returned normally, but some of the response
headers might be incorrect since a document copy is being used. (New in
HTTP 1.1)
|
204
|
No Content
|
No new document; browser should continue to display previous
document. This is a useful if the user periodically reloads a page and
you can determine that the previous page is already up to date. However,
this does not work for pages that are automatically reloaded via the
Refresh response header or the equivalent <META
HTTP-EQUIV="Refresh" ...> header, since returning this status
code stops future reloading. JavaScript-based automatic reloading could
still work in such a case, though.
|
205
|
Reset Content
|
No new document, but browser should reset document view. Used to
force browser to clear CGI form fields. (New in HTTP 1.1)
|
206
|
Partial Content
|
Client sent a partial request with a Range header, and
server has fulfilled it. (New in HTTP 1.1)
|
300
|
Multiple Choices
|
Document requested can be found several places; they'll be listed in
the returned document. If server has a preferred choice, it should be
listed in the Location response header.
|
301
|
Moved Permanently
|
Requested document is elsewhere, and the URL for it is given in the
Location response header. Browsers should automatically
follow the link to the new URL.
|
302
|
Found
|
Similar to 301, except that the new URL should be interpreted as a
temporary replacement, not a permanent one. Note: the message was "Moved
Temporarily" in HTTP 1.0, and the constant in HttpServletResponse
is SC_MOVED_TEMPORARILY, not SC_FOUND.Very
useful header, since browsers automatically follow the link to the new
URL. This status code is so useful that there is a special method for
it, sendRedirect. Using response.sendRedirect(url)
has a couple of advantages over doing
response.setStatus(response.SC_MOVED_TEMPORARILY) and
response.setHeader("Location", url). First, it is easier. Second,
with sendRedirect, the servlet automatically builds a page
containing the link (to show to older browsers that don't automatically
follow redirects). Finally, sendRedirect can handle
relative URLs, automatically translating them to absolute ones.
Note that this status code is sometimes used interchangeably with
301. some servers will send 301 and others will
send 302.
Technically, browsers are only supposed to automatically follow the
redirection if the original request was GET. See the 307
header for details. |
303
|
See Other
|
Like 301/302, except that if the original request was POST,
the redirected document (given in the Location header)
should be retrieved via GET. (New in HTTP 1.1)
|
304
|
Not Modified
|
Client has a cached document and performed a conditional request
(usually by supplying an If-Modified-Since header
indicating that it only wants documents newer than a specified date).
Server wants to tell client that the old, cached document should still
be used.
|
305
|
Use Proxy
|
Requested document should be retrieved via proxy listed in
Location header. (New in HTTP 1.1)
|
307
|
Temporary Redirect
|
This is identical to 302 ("Found" or "Temporarily Moved"). It was
added to HTTP 1.1 since many browsers erroneously followed the
redirection on a 302 response even if the original message was a
POST, even though it really ought to have followed the
redirection of a POST request only on a 303 response. This
response is intended to be unambigously clear: follow redirected
GET and POST requests in the case of 303
responses, only follow the redirection for GET requests in
the case of 307 responses. Note: for some reason there is no constant in
HttpServletResponse corresponding to this status code. (New
in HTTP 1.1)
|
400
|
Bad Request
|
Bad syntax in the request.
|
401
|
Unauthorized
|
Client tried to access password-protected page without proper
authorization. Response should include a WWW-Authenticate
header that the browser would use to pop up a username/password dialog
box, which then comes back via the Authorization header.
|
403
|
Forbidden
|
Resource is not available, regardless of authorization. Often the
result of bad file or directory permissions on the server.
|
404
|
Not Found
|
No resource could be found at that address. This is the standard "no
such page" response. This is such a common and useful response that
there is a special method for it in HttpServletResponse:
sendError(message). The advantage of sendError
over setStatus is that, with sendError, the
server automatically generates an error page showing the error message.
|
405
|
Method Not Allowed
|
The request method (GET, POST, HEAD,
DELETE, PUT, TRACE, etc.) was not
allowed for this particular resource. (New in HTTP 1.1)
|
406
|
Not Acceptable
|
Resource indicated generates a MIME type incompatible with that
specified by the client via its Accept header. (New in HTTP
1.1)
|
407
|
Proxy Authentication Required
|
Similar to 401, but proxy server must return a
Proxy-Authenticate header. (New in HTTP 1.1)
|
408
|
Request Timeout
|
The client took too long to send the request. (New in HTTP 1.1)
|
409
|
Conflict
|
Usually associated with PUT requests; used for
situations such as trying to upload an incorrect version of a file. (New
in HTTP 1.1)
|
410
|
Gone
|
Document is gone; no forwarding address known. Differs from 404 in
that the document is is known to be permanently gone in this case, not
just unavailable for unknown reasons as with 404. (New in HTTP 1.1)
|
411
|
Length Required
|
Server cannot process request unless client sends a
Content-Length header. (New in HTTP 1.1)
|
412
|
Precondition Failed
|
Some precondition specified in the request headers was false. (New
in HTTP 1.1)
|
413
|
Request Entity Too Large
|
The requested document is bigger than the server wants to handle
now. If the server thinks it can handle it later, it should include a
Retry-After header. (New in HTTP 1.1)
|
414
|
Request URI Too Long
|
The URI is too long. (New in HTTP 1.1)
|
415
|
Unsupported Media Type
|
Request is in an unknown format. (New in HTTP 1.1)
|
416
|
Requested Range Not Satisfiable
|
Client included an unsatisfiable Range header in
request. (New in HTTP 1.1)
|
417
|
Expectation Failed
|
Value in the Expect request header could not be met.
(New in HTTP 1.1)
|
500
|
Internal Server Error
|
Generic "server is confused" message. It is often the result of CGI
programs or (heaven forbid!) servlets that crash or return improperly
formatted headers.
|
501
|
Not Implemented
|
Server doesn't support functionality to fulfill request. Used, for
example, when client issues command like PUT that server
doesn't support.
|
502
|
Bad Gateway
|
Used by servers that act as proxies or gateways; indicates that
initial server got a bad response from the remote server.
|
503
|
Service Unavailable
|
Server cannot respond due to maintenance or overloading. For
example, a servlet might return this header if some thread or database
connection pool is currently full. Server can supply a Retry-After
header.
|
504
|
Gateway Timeout
|
Used by servers that act as proxies or gateways; indicates that
initial server didn't get a response from the remote server in time.
(New in HTTP 1.1)
|
505
|
HTTP Version Not Supported
|
Server doesn't support version of HTTP indicated in request line.
(New in HTTP 1.1) |
|
|
|
Keywords:
Handling the Client Request:Form Data,asp net client,asp net data,vb net data,control data,data net,java client,data repeater
|
|
HTML Quizes |
|
XML Quizes |
|
Browser Scripting Quizes |
|
Server Scripting Quizes |
|
.NET (dotnet) Quizes |
|
Multimedia Quizes |
|
Web Building Quizes |
|
Java Quizes |
|
Programming Langauges Quizes |
|
Soft Skills Quizes |
|
Database Quizes |
|
Operating System Quizes |
|
Software Testing Quizes |
|
SAP Module Quizes |
|
Networking Programming Quizes |
|
Microsoft Office Quizes |
|
Accounting Quizes |
|
|