3

can i use servlet for a self implemented HttpServer(com.sun.net.httpserver.HttpServer) in eclipse(The HttpServer should start with the port no. and servlet should handle the client request.) ? if yes sample code would be highly useful.

Manas Pratim Chamuah
  • 1,527
  • 2
  • 15
  • 33
  • we will love to add to your efforts,show up some of your work – nobalG Aug 12 '14 at 11:58
  • Basically yes - if you are building a servlet container - you'll need to initialize and fill the request and response objects before passing them to the servlet. What do you need that for? can you give more hints about your use case? – A4L Aug 12 '14 at 12:04
  • 3
    @A4L I m not able to "connect" my servlet with the HttpServer.I can handle the "GET" and "POST" inside my HttpServer itself(by implementing HttpHandler).But I need to initialize the servlet once the client sends the request to the server so that servlet handles the doGet and doPost instead of HttpHandler. – Manas Pratim Chamuah Aug 12 '14 at 12:19
  • There is much more to a Java Servlet [web container](https://en.wikipedia.org/wiki/Web_container) than an HTTP web server. You would study and implement the 246 page specification for Java Servlet 4 defined on [JSR 369](https://jcp.org/en/jsr/detail?id=369). But what a colossal waste of time and effort, given the existence of Apache Tomcat, Eclipse Jetty, and many more. Why would you bother to roll-your-own? – Basil Bourque Mar 12 '19 at 02:03
  • https://stackoverflow.com/q/49152824/642706 duplicates this Question. – Basil Bourque Mar 12 '19 at 02:08
  • Does this answer your question? [ServletContextListener isn't invoked when using com.sun.net.httpserver.HttpServer](https://stackoverflow.com/questions/53847095/servletcontextlistener-isnt-invoked-when-using-com-sun-net-httpserver-httpserve) – Dmitry Spikhalskiy Aug 02 '22 at 22:47

0 Answers0