You are on page 1of 3

About

Bookstore

RSS

Email

Followus

Becomeafan

JavaExamples
LearnJavaProgrammingbyExamples

Home

1.JavaSEAPI
Servlet

2.JavaEEAPI

3.Frameworks

4.OtherLibraries

5.DesignPatterns

6.IDE/Tools

Searchthissite...
January21,20144:05pm

Youarehere:Home

HowdoIsendaresponsestatusinservlet?

HowdoIsendaresponsestatusinservlet?
PostedbyWayanSaryada onFebruary10,2007

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

package org.kodejava.example.servlet; importjavax.servlet.ServletException; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importjava.io.IOException; public class ResponseStatus extends HttpServlet { protected void doGet(HttpServletRequestrequest, HttpServletResponseresponse) throwsServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequestrequest, HttpServletResponseresponse) throwsServletException, IOException { // //AllresponsestatusisdefinedintheHttpServletResponseclass.We //canthenusetheseconstantsvaluetoreturnprocessstatustothe //browser. // response.setContentType("text/html"); // //LetsaythisservletonlyhandlerequestforpagenameinputForm.So //whenuserrequestforotherpagenameerrorpagenotfound404will //bereturned,otherwiseitwillbe200whichmeanOK. // String page = request.getParameter("page"); if (page != null && page.equals("inputForm")) { response.setStatus(response.SC_OK); } else { response.sendError(response.SC_NOT_FOUND, "Therequestedpage[" + page + "]notfound."); } } }

Find us on Facebook

Learn by Examples
Like

119 people like Learn by Examples.

HereisalistofallavailablestatuscodethataredefinedintheHttpServletResponseclass. StatusCode SC_ACCEPTED SC_BAD_GATEWAY SC_BAD_REQUEST SC_CONFLICT SC_CONTINUE SC_CREATED SC_EXPECTATION_FAILED SC_FORBIDDEN SC_FOUND SC_GATEWAY_TIMEOUT SC_GONE SC_HTTP_VERSION_NOT_SUPPORTED SC_INTERNAL_SERVER_ERROR SC_LENGTH_REQUIRED SC_METHOD_NOT_ALLOWED SC_MOVED_PERMANENTLY completed Statuscode(502)indicatingthattheHTTPserverreceivedaninvalidresponsefroma serveritconsultedwhenactingasaproxyorgateway Statuscode(400)indicatingtherequestsentbytheclientwassyntacticallyincorrect Statuscode(409)indicatingthattherequestcouldnotbecompletedduetoaconflict withthecurrentstateoftheresource Statuscode(100)indicatingtheclientcancontinue Statuscode(201)indicatingtherequestsucceededandcreatedanewresourceonthe server Statuscode(417)indicatingthattheservercouldnotmeettheexpectationgiveninthe Expectrequestheader Statuscode(403)indicatingtheserverunderstoodtherequestbutrefusedtofulfillit Statuscode(302)indicatingthattheresourceresidetemporarilyunderadifferentURI Statuscode(504)indicatingthattheserverdidnotreceiveatimelyresponsefromthe upstreamserverwhileactingasagatewayorproxy Statuscode(410)indicatingthattheresourceisnolongeravailableattheserverand noforwardingaddressisknown Statuscode(505)indicatingthattheserverdoesnotsupportorrefusestosupportthe HTTPprotocolversionthatwasusedintherequestmessage Statuscode(500)indicatinganerrorinsidetheHTTPserverwhichpreventeditfrom fulfillingtherequest Statuscode(411)indicatingthattherequestcannotbehandledwithoutadefined ContentLength Statuscode(405)indicatingthatthemethodspecifiedintheRequestLineisnot allowedfortheresourceidentifiedbytheRequestURI Statuscode(301)indicatingthattheresourcehaspermanentlymovedtoanew location,andthatfuturereferencesshoulduseanewURIwiththeirrequests Statuscode(302)indicatingthattheresourcehastemporarilymovedtoanother SC_MOVED_TEMPORARILY location,butthatfuturereferencesshouldstillusetheoriginalURItoaccessthe Description Statuscode(202)indicatingthatarequestwasacceptedforprocessing,butwasnot
Facebook social plugin

Generated with www.html-to-pdf.net

Page 1 / 3

ContentLength SC_METHOD_NOT_ALLOWED SC_MOVED_PERMANENTLY Statuscode(405)indicatingthatthemethodspecifiedintheRequestLineisnot allowedfortheresourceidentifiedbytheRequestURI Statuscode(301)indicatingthattheresourcehaspermanentlymovedtoanew location,andthatfuturereferencesshoulduseanewURIwiththeirrequests Statuscode(302)indicatingthattheresourcehastemporarilymovedtoanother SC_MOVED_TEMPORARILY location,butthatfuturereferencesshouldstillusetheoriginalURItoaccessthe resource SC_MULTIPLE_CHOICES SC_NO_CONTENT SC_NON_AUTHORITATIVE_INFORMATION Statuscode(300)indicatingthattherequestedresourcecorrespondstoanyoneofa setofrepresentations,eachwithitsownspecificlocation Statuscode(204)indicatingthattherequestsucceededbutthattherewasnonew informationtoreturn Statuscode(203)indicatingthatthemetainformationpresentedbytheclientdidnot originatefromtheserver Statuscode(406)indicatingthattheresourceidentifiedbytherequestisonlycapable SC_NOT_ACCEPTABLE SC_NOT_FOUND SC_NOT_IMPLEMENTED SC_NOT_MODIFIED SC_OK SC_PARTIAL_CONTENT SC_PAYMENT_REQUIRED SC_PRECONDITION_FAILED SC_PROXY_AUTHENTICATION_REQUIRED SC_REQUEST_ENTITY_TOO_LARGE SC_REQUEST_TIMEOUT SC_REQUEST_URI_TOO_LONG ofgeneratingresponseentitieswhichhavecontentcharacteristicsnotacceptable accordingtotheacceptheaderssentintherequest Statuscode(404)indicatingthattherequestedresourceisnotavailable Statuscode(501)indicatingtheHTTPserverdoesnotsupportthefunctionalityneeded tofulfilltherequest Statuscode(304)indicatingthataconditionalGEToperationfoundthattheresource wasavailableandnotmodified Statuscode(200)indicatingtherequestsucceedednormally Statuscode(206)indicatingthattheserverhasfulfilledthepartialGETrequestforthe resource Statuscode(402)reservedforfutureuse Statuscode(412)indicatingthatthepreconditiongiveninoneormoreoftherequest headerfieldsevaluatedtofalsewhenitwastestedontheserver Statuscode(407)indicatingthattheclientMUSTfirstauthenticateitselfwiththeproxy Statuscode(413)indicatingthattheserverisrefusingtoprocesstherequestbecause therequestentityislargerthantheserveriswillingorabletoprocess Statuscode(408)indicatingthattheclientdidnotproducearequestwithinthetimethat theserverwaspreparedtowait Statuscode(414)indicatingthattheserverisrefusingtoservicetherequestbecause theRequestURIislongerthantheserveriswillingtointerpret Statuscode(205)indicatingthattheagentSHOULDresetthedocumentviewwhich causedtherequesttobesent Statuscode(303)indicatingthattheresponsetotherequestcanbefoundundera differentURI Statuscode(503)indicatingthattheHTTPserveristemporarilyoverloaded,andunable tohandletherequest Statuscode(101)indicatingtheserverisswitchingprotocolsaccordingtoUpgrade header Statuscode(307)indicatingthattherequestedresourceresidestemporarilyundera differentURI Statuscode(401)indicatingthattherequestrequiresHTTPauthentication Statuscode(415)indicatingthattheserverisrefusingtoservicetherequestbecause SC_UNSUPPORTED_MEDIA_TYPE theentityoftherequestisinaformatnotsupportedbytherequestedresourceforthe requestedmethod SC_USE_PROXY Statuscode(305)indicatingthattherequestedresourceMUSTbeaccessedthrough theproxygivenbytheLocationfield NeedaClient/Server(MySQL)studentrecord application...

SC_REQUESTED_RANGE_NOT_SATISFIABLEStatuscode(416)indicatingthattheservercannotservetherequestedbyterange SC_RESET_CONTENT SC_SEE_OTHER SC_SERVICE_UNAVAILABLE SC_SWITCHING_PROTOCOLS SC_TEMPORARY_REDIRECT SC_UNAUTHORIZED

WorkfromHome
RecentProjects

$30250

View

$30250

View

RelatedPosts
SimpleJavaProgrammingofWhitepaperScript /Algorithm(Image/Video)(URLfixed!)... HowdoIsendacookieinServlet? HowdoIgetclientIPandhostnameinServlet? HowdoIreadcookieinServlet? HowdoIgetservletrequestURLinformation? HowdoIreadservletinitparameter? HowdoIgetservletrequestheadersinformation? HowdoIdeleteacookieinServlet?
Poweredby

$30250

View

AndroidandIOSforexmarginapp android,ipad,iphone,java,mobilephone,app,... Findmoreprojects

PostaProject

Filedin:Servlet

AboutWayanSaryada
Iamaprogrammer,arunner,anopenwaterdiverandcurrentlylivingintheislandofBali,Indonesia. ViewallpostsbyWayanSaryada

Generated with www.html-to-pdf.net


Name(Required)

LeaveaReply

Page 2 / 3

LeaveaReply
Name(Required) Mail(willnotbepublished)(Required) Website

SubmitComment

Pages
About Bookstore

RecentPosts
HowdoIcreateasimplemail clientprograminSwing? Whatarethesystem propertiesusedforsending email? HowdoIsendanHTML email? HowdoIreadlastncharacters fromafile? JavaSEInstallationTutorial

RecentComments
PierreonHowdoIsendemail usingGmailviaTLS? PreethionHowdoImove focusfromJTextAreausing TABkey? AmitonHowdoIgetoperating systemtemporarydirectory/ folder? SrinonHowtomonitorfileor directorychanges? SrinonHowtomonitorfileor directorychanges?

JavaResources
JavaLanguageSpecification JavaSETechnicalDocumentation JavaTutorials JavaEETechnicalDocumentation JavaEE7Tutorials

AffiliateLinks
ShopTechTitlesonoreilly.com 50%offhostingplansfromGoDaddy!

2014JavaExamples.Allrightsreserved.

Generated with www.html-to-pdf.net

Page 3 / 3

You might also like