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

0 comments:
Post a Comment