Dear Friends.,

Am new to the java world.. I am creating a application where i have to generate a html page from a Dynamic jsp page..

I have tried my best and i was able to create a static html page from a JSP..

But how to fill the data into the HTML is the problem for me,.. Please help me

find the code to generate the HTML file from JSP..

function crehtml()
{
    alert("jaiprakash");
    <%
	String path = "/home/administrator/Raj/jai/output.html";
        String path3 = "fdfdsfjdjsff";
        File file = new File(path);
	Writer wr = new BufferedWriter(new FileWriter(file));
	wr.write("<html><head><title>jai</title>");
        wr.write("<style>");
        // Write the contents of the style sheet into the page
        String styleSheetPath ="/home/administrator/Raj/jai/style.css";
        // Create input stream object.
        FileInputStream fis = new FileInputStream( styleSheetPath );
        // Set variable for looping through bytes.
        int c; 
        while( (c = fis.read() ) != -1) {
          wr.write(c); // Loop to read and write bytes.
        }
        fis.close(); // Close output and input resources. 
        // Done writing out style sheet
        wr.write( "</style>" );
        wr.write("<SCRIPT>");
        wr.write("function  dddd(){ ");
        wr.write("var name =\"jpai\";");
        wr.write("var age = \"jpai\";");
        wr.write("var ade = \"jpai\";");
        wr.write("var check = \"jpai\";");          
        wr.write("document.getElementById(\"name\").innerHTML = \"<p>\"+name+\"<br/>\"+age+\"<br/>\"+ade+\"<br/>\"+check+\"</p>\";");
        wr.write("}</SCRIPT>");
        wr.write("</head>");
        wr.write("<body onLoad=dddd()>");
        wr.write("<table>");
        wr.write("<tr><td>");
        wr.write("<table width=\"900px\" cellpadding=\"2\" cellspacing=\"0\" class=\"table\">");
        wr.write("<tbody ><tr height=\"100px\" class=\"tr1\">");
        wr.write("<td width=\"125px\">");
        wr.write("<p><b>Order ID:<br/>Order Date:<br/>Order Type:<br/>Parent ID:</b></p></td>");
        wr.write("<td id=\"orderid\" width=\"125px\">&nbsp;</td>");
        wr.write("<td width=\"150px\"><p><b>Customer:<br/>Sales Exec:<br/>CO Reference:<br/>Partner ID:</b></p></td>");
        wr.write("<td width=\"150px\" id=\"customername\">&nbsp;</td>");
        wr.write("<td width=\"350px\" class=\"tr2\"><div id=\"billingaddress\">&nbsp;</div></td></tr></tbody>");           
        wr.write("</table>");
        wr.write("</td></tr><tr><td>");
        wr.write("<table width=\"900px\" class=\"table\" align=\"left\" id=\"productTable\" cellpadding=\"3\">");
        wr.write("<thead>");
        wr.write("<th class=\"th\" width=\"8%\">Sl.No.</th>");
        wr.write("<th class=\"th\" width=\"12%\">jai Id</th>");
        wr.write("<th class=\"th\" width=\"13%\">Description</th>");
        wr.write("<th class=\"th\" width=\"10%\">jai Name</th>");
        wr.write("<th class=\"th\" width=\"15%\">Features</th>");
        wr.write("<th class=\"th\" width=\"10%\">Period</th>");
        wr.write("<th class=\"th\" width=\"8%\">Qty</th>");
        wr.write(" <th class=\"th\" width=\"8%\">Time Units</th>");
        wr.write("<th class=\"th\" width=\"8%\">Rate</th>");
        wr.write("<th class=\"th\" width=\"8%\">Total</th>");
        wr.write("</thead>");
        wr.write("<tfoot>");
        wr.write("<th width=\"8%\">&nbsp;</th>");
        wr.write("<th width=\"12%\">&nbsp;</th>");
        wr.write("<th width=\"13%\">&nbsp;</th>");
        wr.write("<th width=\"10%\">&nbsp;</th>");
        wr.write("<th width=\"15%\">&nbsp;</th>");
        wr.write("<th width=\"10%\">&nbsp;</th>");
        wr.write("<th width=\"8%\">&nbsp;</th>");
        wr.write("<th width=\"8%\">&nbsp;</th>");
        wr.write("<th width=\"8%\"><p>Total:<br/>Discount:<br/><br/>NetValue:</p></th>");
        wr.write("<th width=\"8%\">");
        wr.write("<p><label id=\"totvalue\" name=\"totvalue\">&nbsp;</label><br/>");
        wr.write("<label id=\"discount\" name=\"discount\">&nbsp;</label><br/>");
        wr.write("_______");
        wr.write("<label id=\"orderval\" name=\"orderval\">&nbsp;</label></p>");
        wr.write("</th></tfoot></table></td></tr><tr><td>");
        wr.write("<table align=\"left\" cellpadding=\"3\" cellspacing=\"2\" class=\"table\">");
        wr.write("<thead><th class=\"th\" align=\"left\">");
        wr.write("<font class=\"fontheader1\" id=\"actionheader\">Action Details - 0</font>");
        wr.write("</th></thead><tbody><tr><td>");
        wr.write("<table id=\"orderactions\"><tbody>");
        wr.write("</tbody></table></td></tr></tbody></table></td></tr>");
        wr.write("</table>");
        wr.write("</body>");
        wr.write("</html>");
  	wr.flush();
	wr.close();

%>
    }

css file

/*body {background-color: yellow} h1 {font-size: 36pt} h2 {color: blue} p {margin-left: 50px}*/



body {

	background: #FFFFFF;

	margin: 0;

	font-family: 12px, Verdana, Helvetica, Arial, sans-serif;

	color: #292929;

	margin: 0;

}





p {



	font-family: Verdana, Helvetica, Arial;



	font-size: 12px;



	color: #292929;



	font-weight: normal;



	line-height: 18px;

		

	text-align: justify;

}



.submit



{



    BORDER-RIGHT: lightgrey thin outset;



    BORDER-TOP: lightgrey thin outset;



    FONT-SIZE: 8pt;



    BORDER-LEFT: lightgrey thin outset;



    COLOR: #000000;



    BORDER-BOTTOM: lightgrey thin outset;



    FONT-FAMILY: Arial, Helvetica, sans-serif;



    LETTER-SPACING: 1px;



	BACKGROUND: #DEE5EB;



}



TEXTAREA



{



	FONT-SIZE: 11px;



	FONT-FAMILY: Tahoma, Arial;



	color: #292929;



	border: 1px solid #7F9DB9;



}



.heading {



	font-family: Verdana, Arial, Helvetica, sans-serif;



	font-size: 13px;



	font-weight: bold;



	color: #FFFFFF;



}



.text {



	font-family: Tahoma, Arial;



	font-size: 11px;



	color: #333333;



	font-weight: normal;



	line-height: 18px;



}



select {



	FONT-FAMILY: Tahoma, Arial;



	font-size: 11px;



	line-height: 18px;



	font-weight: normal;



	color: #292929;



	text-decoration: none;

	

	border: 1px solid #7F9DB9;



}



.select {



	FONT-FAMILY: Tahoma, Arial;



	font-size: 11px;



	line-height: 18px;



	font-weight: normal;



	color: #292929;



	text-decoration: none;

	

	border: 1px solid #7F9DB9;

        

}



.para {

	font-family: Tahoma, Arial;

	font-size: 11px;

	color: #60656C;

	line-height: 18px;

	text-align: justify;

	font-weight: normal;



}



.bg_body_bottom {



	background-image: url(images/body_bottom.jpg);



	background-repeat: no-repeat;



	background-position: center bottom;



}







input {



	FONT-SIZE: 11px;



	FONT-FAMILY: Tahoma, Arial;



	color: #292929;



	border: 1px solid #7F9DB9;



}



.colorbox {



	background-color: #FFFFCC;



	text-align: justify;



	border: 1px solid #CDD6DD;



	font-family: Tahoma, Verdana, Arial;



	font-size: 11px;



	color: #333333;



	line-height: 16px;



}



strong {



	font-family: Tahoma, Verdana, Arial;



	font-size: 11px;



	font-weight: bold;



	color: #000000;



}



table

{

	border-collapse: separate;



	empty-cells: show;

}



fieldset{

	border: 1px solid #7F9DB9;        

        

}







#fieldset1{

	border: 1px solid #7F9DB9;

        width: 390px;

}



#fieldset2{

	border: 1px solid #7F9DB9;

        width: 390px;

}



.rightcoldiv h2 {

	margin: 0 0 5;

	font-size: 16px;

	padding: 3px 0px 3px 10px;

	color: white;

	padding: 3px 0px 3px 10px;

	border-bottom-width: 1px;

	border-bottom-style: solid;

	border-bottom-color: #e27901;

	background-color: #1869BD;

	background-repeat: repeat;

}



.bluetext {

    color: #5584B0;

    font: menu;

    font-size: 13px;

}



.blueboldtext {

    color: #5584B0;

    font: menu;

    font-size: 13px;

    font-weight: bold;

}



.fontstyle1{

    font-family: Verdana, Helvetica, Arial;

    font-size: 9px;

    font-color: #000000;

    font-weight: normal;

    line-height: 11px;

    text-align: justify;

}



.fontheader1{

    font-family: Verdana, Helvetica, Arial;

    font-size: 11px;

    font-color: #000000;

    font-weight: bold;

    line-height: 12px;

    text-align: justify;

}



/*----siva-------------*/

.table

{

	border-collapse: separate;

	

	empty-cells: show;



	/*border: 2px outset #7F9DB9 ;*/

}



.tblCardView{

    border-collapse: separate;

    empty-cells: show;

    /*border: 2px outset #7F9DB9 ;*/

}







.td{

	FONT-SIZE: 14px;



	FONT-FAMILY: Tahoma, Arial;



	color: #000000;

	

	border-color: #ECF9FF;



	border-style: ridge;

         

}



.td1{

        background-color: #DAE4F0;

        

        border-top: dashed thin black;

        

        border-bottom: dashed thin black;

        

        border-left: dashed thin black;

        

        border-right: dashed thin black;

}



.tr1{

	

	background-color: #DAE4F0;

        border-top: solid thin black;

        border-bottom: solid thin black;

        border-left: solid thin black;

        border-right: solid thin black;

}



.tr2{

	background-color: #C4D3E6;

        border-top: solid thin black;

        border-bottom: solid thin black;

        border-left: solid thin black;

        border-right: solid thin black;

}



.th{

	background-color: #B0C4DD;

	

	FONT-SIZE: 11px;



	FONT-FAMILY: Tahoma, Arial;



	color: #000000;

	

	border-color: #ECF9FF;



	/*border-style: ridge;*/

}



.outerborder{

    border-top: solid thin;

    border-bottom: solid thin;

    border-left: solid thin;

    border-right: solid thin;

}







.tdLabel{

    text-align: left;

    width: 40%

}



.label{

    font-family: Arial,Helvetica,sans-serif;

    font-size: 12px;

    

}



.boxheading {

    padding: 5px 0;

    text-indent: 10px;

    background: #F7F7F7;

    /*display: block;*/

    border-bottom: 1px solid #DDD;

    color: #4A69A5;

    text-decoration: none;

}



.columnHeading{

    padding: 5px 0;

    text-indent: 10px;

    background: #F7F7F7;

    /*display: block;*/

    border-bottom: 1px solid #DDD;

    color: #4A69A5;

    text-decoration: none;

    font-weight: strong;

}





.urPcBodyPln{background-color:#FFF;font-family:Arial,Helvetica,sans-serif;font-size:medium}

now i have to fill some value to this html page from the jsp page.. means i have to get the value from the jsp page and fill it here.. please help

Hello,

What is the point of writing out the html in the manner indicated? We probably don't have enough information to solve the problem, but here are a few general thoughts.

If you are intending to generate some data on the server and inject that data into the page, using the page as the display mechanism for dynamically-generated information, then you should use the MVC, or "Model View Controller" design. Basically, you should have a JSP designed to hold your data (View), a separate Java class that generates your data (Model) and a servlet that injects your data into the View (Controller).

This is not complicated to implement.

You can also use a JavaBean, which is just a special kind of Java class that you can call directly from your JSP, and which again is just a way to do some kind of serverside data processing, and use the JSP to display the results. A Bean is probably more suitable if your data is not being generated as a result of interaction with the visitor. For example, I have a calendar on a web site that is generated on every page by a JavaBean.

It definitely is not recommended to write out huge blocks of HTML from your Java class/servlet or within the JSP. This HTML should be created as a template and your data written into the template. If you want to include a file in a JSP, use the .jspf mechanism, e.g.

<%@include file="/WEB-INF/jspf/header.jspf" %>

I recommend the book Head First Servlets & JSP, which has an excellent tutorial for writing a simple MVC application, as well as everything else you need to know to write server applications.

Thanks.

mp

I have to finish this work in 4 days... how could it possible for me to read javabean..servlets and MVC.. Anyways thanks for the quick response.. Please let me know if there is any other way to do this..

I have to finish this work in 4 days... how could it possible for me to read javabean..servlets and MVC.. Anyways thanks for the quick response.. Please let me know if there is any other way to do this..

Hello,

I need a clearer statement of what "this work" is ... are you processing a form and displaying the results? Are you reading data from a file and displaying it? Are you performing some other kind of work on the server and displaying the output?

The solution depends on the problem.

Here is a trivial example of using a JavaBean. I have a site NavigationBean class that builds some menus and does some related navigation stuff on a site. Among other things, it has a facility for dynamically setting the page title, like this.

<%@page pageEncoding="UTF-8" info="Gallery"%>

<jsp:useBean id="navigation" scope="page" class="org.mistysplace.utility.NavigationBean">
  <jsp:setProperty name="navigation" property="pageName" value="<%= this.getServletInfo() %>"></jsp:setProperty>
</jsp:useBean>

This code is called like this:

<title>Mistysplace::${navigation.pageName}</title>

The point is, whenever I add a page to the site, it gets its unique page name automatically. I don't have to fiddle with the HTML <title> element, which is just treated like a template. (All of the HTML for the page <head> element is contained in a .jspf include file and is put on the pages through an include.)

I understand about being in a hurry and having to meet a deadline. But good preparation up front is necessary to reach the finish properly. A few hours thought and study now can save a day of work later.

Thanks.

mp

This article has been dead for over six months. Start a new discussion instead.