Servlet Source Code

Source: Internet
Author: User
[C-sharp]View plaincopy
  1. Protected void Service (httpservletrequest req, httpservletresponse resp)
  2. Throws servletexception, ioexception
  3. {
  4. String method = Req. getmethod ();
  5. If (method. Equals ("get "))
  6. {
  7. Long lastmodified = getlastmodified (req );
  8. If (lastmodified =-1l)
  9. {
  10. Doget (req, resp );
  11. } Else
  12. {
  13. Long ifmodifiedsince = Req. getdateheader ("If-modified-since ");
  14. If (ifmodifiedsince <(lastmodified/1000l) * 1000l)
  15. {
  16. Maybesetlastmodified (resp, lastmodified );
  17. Doget (req, resp );
  18. } Else
  19. {
  20. Resp. setstatus (304 );
  21. }
  22. }
  23. } Else
  24. If (method. Equals ("head "))
  25. {
  26. Long lastmodified = getlastmodified (req );
  27. Maybesetlastmodified (resp, lastmodified );
  28. Dohead (req, resp );
  29. } Else
  30. If (method. Equals ("Post "))
  31. Dopost (req, resp );
  32. Else
  33. If (method. Equals ("put "))
  34. Doput (req, resp );
  35. Else
  36. If (method. Equals ("delete "))
  37. Dodelete (req, resp );
  38. Else
  39. If (method. Equals ("options "))
  40. Dooptions (req, resp );
  41. Else
  42. If (method. Equals ("trace "))
  43. {
  44. Dotrace (req, resp );
  45. } Else
  46. {
  47. String errmsg = lstrings. getstring ("HTTP. method_not_implemented ");
  48. Object errargs [] = new object [1];
  49. Errargs [0] = method;
  50. Errmsg = messageformat. Format (errmsg, errargs );
  51. Resp. senderror (501, errmsg );
  52. }
  53. }

Servlet Source Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.