Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question 994784367093

 
Timber Lee
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question ID :994784367093
Which statement regarding the following method of class HttpServlet is correct?
doOptions(HttpServletRequest, HttpServletResponse);
1.it is call when container receives HTTP PUT request,
2,it is call when container receives HTTP POST request,
3,it is call when container receives HTTP FORM request,
4,it is call when container receives HTTP HEAD request,
 
AJAY RANA
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Lee,
The answer would be "None of these" as this method would be called on OPTIONS request.
This is from API :
" Called by the server (via the service method) to allow a servlet to handle a OPTIONS request. The OPTIONS request determines which HTTP methods the server supports and returns an appropriate header".
Regards ,
Ajay Rana
 
kavitha yalamanchili
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajay,
How does doOptions get called in the first place?
If I have method as OPTIONS in my JSP.. it is always the doGet that is being called..
Iam a little confused here.. why is doGet being called?
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kavitay,
a construct like
<select>
<option>kavitay option
<option>axel option
</select>
is not meant here.
Its about method of http request.
URL requests allways generate a HTTP-GET.
With <form> tag you can send different requests to the browser.
like:
<form action="/cgi-bin/auswert.pl" method="post" target="Daten">
or
<form action="/cgi-bin/auswert.pl" method="options" target="Daten">
 
kavitha yalamanchili
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the line of code that I had in my jsp
<form method="OPTIONS" action="../servlet/HelloWorldServlet">
and in HelloWorldServlet I had doGet, doPost and doOptions methods.
now when I load my JSP I see the message that I have in doGet.
so when the method="OPTIONS" is given in the JSP, it is doGet that is being called. Can someone explain why doGet is called?
I think what happens is may be doOptions is called when ever service method is called to check if the method that is being requested is allowed or not. Iam not sure..
 
Timber Lee
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,kavitha, do you try PUT and HEAD ? is doGet() called?
 
kavitha yalamanchili
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, doGet is called if the methods are the ones u mentioned
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic