Thursday, 12 November 2015

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 it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

9 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. This is one of the most wonderful blog, this is work is tremendous. Thanks
    Time Management

    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. 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

  4. 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
  5. thanks for sharing technical blog for java coding. its really very useful for us. thanks for sharing.
    JAVA TRAINING

    ReplyDelete
  6. Please let me know if you're looking for a article writer for your blog. You have some really great articles and I feel I would be a good asset. If you ever want to take some of the load off, I'd love to write some articles for your blog in exchange for a link back to mine. Please send me an email if interested. Cheers! PHP Training in Jalandhar

    ReplyDelete
  7. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

    Online Java Training Online Java Training | Java EE Training Institute in Chennai

    ReplyDelete
  8. Superb article on Java Programming. But, it takes some time to understand to me. I am middle of the learning to Java..

    ReplyDelete