Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How to create html pages by compiling servlets code?

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!