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 Java Code to Generate HTML form](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9dqkxYffCnraFJBWXK4OGovhDQzhZCKZmB3AOpoBRmtzOwq2ZyM1Clg0wYfSRHUmP5r8fSyx0eXfWrpLEdDRJTUnKLWFp0Vn5q8eSyhhV9-KqW0bzfx9HkGsP4NwYZrwZo8fGclFoi20/s640/Java+Code+to+Generate+HTML+form.png)
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.
ReplyDeleteI agree with your post! This is one of the most wonderful articles According to me.
LG Laptop repairs & LG Notebook repairs & LG Projector repairs
ReplyDeleteI agree with your post! This is one of the most wonderful articles According to me.
LG Laptop repairs & LG Notebook repairs & LG Projector repairs
thanks for sharing technical blog for java coding. its really very useful for us. thanks for sharing.
ReplyDeleteJAVA TRAINING
Erst you beautification your course you ought to be fit to interpret the confounded programming module.java programming
ReplyDelete