• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to output HTML from Java 6 web server?

 
Siegfried Heintze
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is my java6 web server and (surprise!) it even works!

Now how do I enhance it to reinvent apache tomcat?
I'm specifically interested in making it serve HTML, servlets JSP and SOAP?
Thanks,
siegfried
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess my question would be, why do you want to do that? Why not just use Tomcat or one of the other java servers? If you want something lightweight and embeddable try Jetty (http://jetty.mortbay.org).

Writing your own server completely from scratch is quite an undertaking. You need to consider the proper implementation of all the protocols you support, security, scalability, etc.

If its just a fun personal project, you should look at how the big projects do it... they are all open source.
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just noticed... you are also using "com.sun.*" packages. You should remember that these are not part of the official Java API and are not supported. Thy could disappear from the API without warning or deprecation.
Generally they should only be used in extreme circumstances, if ever.
 
Siegfried Heintze
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the input.
Please see http://forum.java.sun.com/thread.jspa?messageID=9600114
Is it your opinion that sun.* and com.sun.* are both subject to change and should not be used?

This is a sample program I got from a sun tutorial on the new features of Java 6. Sun is advocating the use of the com.sun classes in these tutorials. They consider these com.sun classes as part of the Java 6 release. Yeah I thought it was strange too.

I need to give a presentation on Java6 and it seemed odd to me that sun would release a web server API was was so brain damaged that it could only output text/plain. Surely there is at least a way to output text/html! It seems logical that they would also incorporate JSP, servlets, and SOAP since they are advocating this features (especially SOAP).

So what do you think? Is my logic reasonable? Can this web server do something besides plain/text?

Siegfried
 
M Easter
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first use of the embedded Http server was a "mind-blower" for me as well.

However, remember that it is "light-weight". Sun expressly states that it is only a partial implementation of HTTP 1.1.

http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/index.html

However, there is an SPI so that you could write your own Http server if you wanted. Though I think it might be wiser to pick up a book on how Tomcat/Apache works and/or look at the source directly. I can't speak for you, but re-inventing Tomcat from scratch sounds painful to me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!