Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes How to create html  pages by compiling servlets code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to create html  pages by compiling servlets code?" Watch "How to create html  pages by compiling servlets code?" New topic
Author

How to create html pages by compiling servlets code?

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi ALL,
I am using JSDK2.1, I am trying to compile a small servlet, i get .java file as well .class file but it doesnt create a .html page , do i need to create a html page and the embed the servlet code?
Thanks very much
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
You would need to create an html or jsp file to run the servlet. A servlet is a compiled class module where the source is in the .java file and the compiled class is in the .class file. Let me know if you need additional information.
Tom P
Ranch Hand

Joined: May 06, 2000
Posts: 88
NO! The servlet does not need an HTML or JSP file. The servlet can simply write HTML. The class file is run by specifying the servlet URL the same way that you run a CGI program. Compiling a servlet does not magically create an HTML file. Running the compiled class file from the browser thorugh the web server sends HTML to the browser.
Steps:
1) Create .java
2) Compile .java into .class
3) run the class file from your browser specifying the address of your web server's servlet directory (e.g. http://www.a.com/servlet/MyServlet)
[This message has been edited by Tom P (edited May 15, 2000).]
Aaron Robinson
Ranch Hand

Joined: May 15, 2000
Posts: 46
Originally posted by Shiva:
Hi ALL,
I am using JSDK2.1, I am trying to compile a small servlet, i get .java file as well .class file but it doesnt create a .html page , do i need to create a html page and the embed the servlet code?
Thanks very much

You generally create a servlet and then simply compile it. It never generates an HTML file. Withing this servlet you would output the HTML using System.out.println.
Of course this meant that the HTML was not particularly easy to maintain so JSPs were created. These look like normal HTML except they has JSP tags inside them. They enable you to maintain the HTML as you would a normal page. At run time when the JSP is requested for the first time, the JSP page is converted into a servlet (which contains the less manageable system.out.println commands) and then this servlet is compiled as per any other servlet.
Hope this helps.

SCJP 1.0,1.1,2 SCJA 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create html pages by compiling servlets code?
 
Similar Threads
session lost with window.open()
Problems getting Tomcat to work without Eclipse IDE
CREATING FILE FROM SERVLET
Not getting control in Servlet
[solved]Problem with servlet session management