Java Code to Generate HTML form

This is the simple Java program that converts the user inputs in to HTML form (paragraph). You can use this HTML document in any web document. The basic purpose behind this code us to give a understanding to the beginners about the connectivity of Java with different web platform.

Source Code 


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lep;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

/**
 *
 * @author UzairYousafZai
 */
public class produceHTMLfromJava {

/**
     * @param args the command line arguments
     */
public static void main(String[] args) throws IOException {
start();
}

private static void start() throws IOException {
String html = generate_HTML_string();
generate_HTML_file(html);

}

private static String generate_HTML_string() throws IOException {
System.out.println("generateTheTicket()");
StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.append("<html>");
htmlBuilder.append("<head><title>Hello World</title></head>");
htmlBuilder.append("<body><p>"+getParagraph1()+"<br>"+ getParagraph2()+"</p></body>");
htmlBuilder.append("</html>");
String html = htmlBuilder.toString();
return html;
}

private static void generate_HTML_file(String html) throws FileNotFoundException, UnsupportedEncodingException {
PrintWriter writer = new PrintWriter("name.html", "UTF-8");
writer.println(html);
writer.close();
}

private static String getParagraph1() throws IOException {
System.out.println("Enter First Paragraph");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
return s;
}

private static String getParagraph2() throws IOException {
System.out.println("Enter Second Paragraph");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
return s;
}

}

Output of the Program

Java Code to Generate HTML form






Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.

4 comments:


  1. I agree with your post! This is one of the most wonderful articles According to me.


    LG Laptop repairs & LG Notebook repairs & LG Projector repairs



    ReplyDelete

  2. I agree with your post! This is one of the most wonderful articles According to me.


    LG Laptop repairs & LG Notebook repairs & LG Projector repairs



    ReplyDelete
  3. thanks for sharing technical blog for java coding. its really very useful for us. thanks for sharing.
    JAVA TRAINING

    ReplyDelete
  4. Erst you beautification your course you ought to be fit to interpret the confounded programming module.java programming

    ReplyDelete