Results 1 to 4 of 4
  1. #1
    magda is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default putting html into java

    Hi, I'm writing an application which has to create a html document and display some information in it. The usual way to do it is with a servlet.
    I've read a little about servlets and understood that usually you use them when you have a web application: for example there is a web page where a user can enter some data and then the servlet processes it and changes the web page according to the entered data.
    I don't need to change the html dynamically all I need is to create it using some data that is first created by a java application and send it to user, who is only going to read the content of the page and click some links.
    Would I need a servlet in this case?
    I still need to create the web page and all I can find is about putting java into html. How can I do it the other way round: write java application which will create html?
    I'll appreciate any suggestions. Thanks.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    Servlets, or JSP pages, are really the best way to do this. Before servlets, there was the common gateway interface, which the web server used the standard input, standard output and environment variables to invoke and communicate with an operating system executable program. I guess we could make a shell script that sets up a class path and launches a java application as a CGI style invocation. I never thought of doing that. I mean, the servlet container is so mature and sensible to do, it just never occured to me to create a CGI mode application. hmm.

    So if you plan to create the html as a one time output html to a file, like the same kind of manually run the tool to generate html and then use the html file from the web server many many times over, without invoking the java tool each time, then I would say sure, let's make a java program that does html output writing:

    Java Code:
     import java.io.File;
    import java.io.IOException;
    import java.io.PrintStream;
    
    /**
     *Created on Jan 26, 2010
     */
    
    /**
     * @author thein
     *
     */
    public class HtmlPrinter {
      public static void main(String[] args) throws IOException {
       PrintStream out = new PrintStream(new File("index.html"));
       out.println("<html>");
       out.println("<body>");
       out.println("We should really do this with servlets or JSP instead.<br/>");
       out.println("Seriously, go look into tomcat. You will find the experience rewarding and educational.<br/>");
       out.println("<p>Tomcat comes with several example web applications and JSP pages, that should help you get started");
       out.println("in writing a JSP file to print out HTML for you.</p>");
       out.println("</body>");
       out.println("</html>");
       out.close();
      }
    }

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by magda View Post
    I don't need to change the html dynamically all I need is to create it using some data that is first created by a java application and send it to user, who is only going to read the content of the page and click some links.
    Um, that is therefore dynamically generated HTML. If it isn't simply a static HTML page (ie somepage.html) then it is, by nature, dynamic.

  4. #4
    magda is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    Thanks for advice, travishein. I'll do it with JSP to get the rewarding and educational experience. :)

Similar Threads

  1. Putting image into program
    By SprayAndPray69 in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 04:38 AM
  2. Putting Image into Java applet
    By SprayAndPray69 in forum New To Java
    Replies: 1
    Last Post: 02-13-2009, 07:14 AM
  3. Putting code together.
    By newbee in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 04:53 AM
  4. Putting your own type in a Set
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 08:32 PM
  5. Putting controls in arrays?
    By Cymro in forum New To Java
    Replies: 4
    Last Post: 02-01-2008, 07:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •