943,961 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 3981
  • JSP RSS
Apr 22nd, 2009
0

Create HTML file from Dynamic JSP

Expand Post »
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..

JSP Syntax (Toggle Plain Text)
  1. function crehtml()
  2. {
  3. alert("jaiprakash");
  4. <%
  5. String path = "/home/administrator/Raj/jai/output.html";
  6. String path3 = "fdfdsfjdjsff";
  7. File file = new File(path);
  8. Writer wr = new BufferedWriter(new FileWriter(file));
  9. wr.write("<html><head><title>jai</title>");
  10. wr.write("<style>");
  11. // Write the contents of the style sheet into the page
  12. String styleSheetPath ="/home/administrator/Raj/jai/style.css";
  13. // Create input stream object.
  14. FileInputStream fis = new FileInputStream( styleSheetPath );
  15. // Set variable for looping through bytes.
  16. int c;
  17. while( (c = fis.read() ) != -1) {
  18. wr.write(c); // Loop to read and write bytes.
  19. }
  20. fis.close(); // Close output and input resources.
  21. // Done writing out style sheet
  22. wr.write( "</style>" );
  23. wr.write("<SCRIPT>");
  24. wr.write("function dddd(){ ");
  25. wr.write("var name =\"jpai\";");
  26. wr.write("var age = \"jpai\";");
  27. wr.write("var ade = \"jpai\";");
  28. wr.write("var check = \"jpai\";");
  29. wr.write("document.getElementById(\"name\").innerHTML = \"<p>\"+name+\"<br/>\"+age+\"<br/>\"+ade+\"<br/>\"+check+\"</p>\";");
  30. wr.write("}</SCRIPT>");
  31. wr.write("</head>");
  32. wr.write("<body onLoad=dddd()>");
  33. wr.write("<table>");
  34. wr.write("<tr><td>");
  35. wr.write("<table width=\"900px\" cellpadding=\"2\" cellspacing=\"0\" class=\"table\">");
  36. wr.write("<tbody ><tr height=\"100px\" class=\"tr1\">");
  37. wr.write("<td width=\"125px\">");
  38. wr.write("<p><b>Order ID:<br/>Order Date:<br/>Order Type:<br/>Parent ID:</b></p></td>");
  39. wr.write("<td id=\"orderid\" width=\"125px\">&nbsp;</td>");
  40. wr.write("<td width=\"150px\"><p><b>Customer:<br/>Sales Exec:<br/>CO Reference:<br/>Partner ID:</b></p></td>");
  41. wr.write("<td width=\"150px\" id=\"customername\">&nbsp;</td>");
  42. wr.write("<td width=\"350px\" class=\"tr2\"><div id=\"billingaddress\">&nbsp;</div></td></tr></tbody>");
  43. wr.write("</table>");
  44. wr.write("</td></tr><tr><td>");
  45. wr.write("<table width=\"900px\" class=\"table\" align=\"left\" id=\"productTable\" cellpadding=\"3\">");
  46. wr.write("<thead>");
  47. wr.write("<th class=\"th\" width=\"8%\">Sl.No.</th>");
  48. wr.write("<th class=\"th\" width=\"12%\">jai Id</th>");
  49. wr.write("<th class=\"th\" width=\"13%\">Description</th>");
  50. wr.write("<th class=\"th\" width=\"10%\">jai Name</th>");
  51. wr.write("<th class=\"th\" width=\"15%\">Features</th>");
  52. wr.write("<th class=\"th\" width=\"10%\">Period</th>");
  53. wr.write("<th class=\"th\" width=\"8%\">Qty</th>");
  54. wr.write(" <th class=\"th\" width=\"8%\">Time Units</th>");
  55. wr.write("<th class=\"th\" width=\"8%\">Rate</th>");
  56. wr.write("<th class=\"th\" width=\"8%\">Total</th>");
  57. wr.write("</thead>");
  58. wr.write("<tfoot>");
  59. wr.write("<th width=\"8%\">&nbsp;</th>");
  60. wr.write("<th width=\"12%\">&nbsp;</th>");
  61. wr.write("<th width=\"13%\">&nbsp;</th>");
  62. wr.write("<th width=\"10%\">&nbsp;</th>");
  63. wr.write("<th width=\"15%\">&nbsp;</th>");
  64. wr.write("<th width=\"10%\">&nbsp;</th>");
  65. wr.write("<th width=\"8%\">&nbsp;</th>");
  66. wr.write("<th width=\"8%\">&nbsp;</th>");
  67. wr.write("<th width=\"8%\"><p>Total:<br/>Discount:<br/><br/>NetValue:</p></th>");
  68. wr.write("<th width=\"8%\">");
  69. wr.write("<p><label id=\"totvalue\" name=\"totvalue\">&nbsp;</label><br/>");
  70. wr.write("<label id=\"discount\" name=\"discount\">&nbsp;</label><br/>");
  71. wr.write("_______");
  72. wr.write("<label id=\"orderval\" name=\"orderval\">&nbsp;</label></p>");
  73. wr.write("</th></tfoot></table></td></tr><tr><td>");
  74. wr.write("<table align=\"left\" cellpadding=\"3\" cellspacing=\"2\" class=\"table\">");
  75. wr.write("<thead><th class=\"th\" align=\"left\">");
  76. wr.write("<font class=\"fontheader1\" id=\"actionheader\">Action Details - 0</font>");
  77. wr.write("</th></thead><tbody><tr><td>");
  78. wr.write("<table id=\"orderactions\"><tbody>");
  79. wr.write("</tbody></table></td></tr></tbody></table></td></tr>");
  80. wr.write("</table>");
  81. wr.write("</body>");
  82. wr.write("</html>");
  83. wr.flush();
  84. wr.close();
  85.  
  86. %>
  87. }

css file

JSP Syntax (Toggle Plain Text)
  1. /*body {background-color: yellow} h1 {font-size: 36pt} h2 {color: blue} p {margin-left: 50px}*/
  2.  
  3.  
  4.  
  5. body {
  6.  
  7. background: #FFFFFF;
  8.  
  9. margin: 0;
  10.  
  11. font-family: 12px, Verdana, Helvetica, Arial, sans-serif;
  12.  
  13. color: #292929;
  14.  
  15. margin: 0;
  16.  
  17. }
  18.  
  19.  
  20.  
  21.  
  22.  
  23. p {
  24.  
  25.  
  26.  
  27. font-family: Verdana, Helvetica, Arial;
  28.  
  29.  
  30.  
  31. font-size: 12px;
  32.  
  33.  
  34.  
  35. color: #292929;
  36.  
  37.  
  38.  
  39. font-weight: normal;
  40.  
  41.  
  42.  
  43. line-height: 18px;
  44.  
  45.  
  46.  
  47. text-align: justify;
  48.  
  49. }
  50.  
  51.  
  52.  
  53. .submit
  54.  
  55.  
  56.  
  57. {
  58.  
  59.  
  60.  
  61. BORDER-RIGHT: lightgrey thin outset;
  62.  
  63.  
  64.  
  65. BORDER-TOP: lightgrey thin outset;
  66.  
  67.  
  68.  
  69. FONT-SIZE: 8pt;
  70.  
  71.  
  72.  
  73. BORDER-LEFT: lightgrey thin outset;
  74.  
  75.  
  76.  
  77. COLOR: #000000;
  78.  
  79.  
  80.  
  81. BORDER-BOTTOM: lightgrey thin outset;
  82.  
  83.  
  84.  
  85. FONT-FAMILY: Arial, Helvetica, sans-serif;
  86.  
  87.  
  88.  
  89. LETTER-SPACING: 1px;
  90.  
  91.  
  92.  
  93. BACKGROUND: #DEE5EB;
  94.  
  95.  
  96.  
  97. }
  98.  
  99.  
  100.  
  101. TEXTAREA
  102.  
  103.  
  104.  
  105. {
  106.  
  107.  
  108.  
  109. FONT-SIZE: 11px;
  110.  
  111.  
  112.  
  113. FONT-FAMILY: Tahoma, Arial;
  114.  
  115.  
  116.  
  117. color: #292929;
  118.  
  119.  
  120.  
  121. border: 1px solid #7F9DB9;
  122.  
  123.  
  124.  
  125. }
  126.  
  127.  
  128.  
  129. .heading {
  130.  
  131.  
  132.  
  133. font-family: Verdana, Arial, Helvetica, sans-serif;
  134.  
  135.  
  136.  
  137. font-size: 13px;
  138.  
  139.  
  140.  
  141. font-weight: bold;
  142.  
  143.  
  144.  
  145. color: #FFFFFF;
  146.  
  147.  
  148.  
  149. }
  150.  
  151.  
  152.  
  153. .text {
  154.  
  155.  
  156.  
  157. font-family: Tahoma, Arial;
  158.  
  159.  
  160.  
  161. font-size: 11px;
  162.  
  163.  
  164.  
  165. color: #333333;
  166.  
  167.  
  168.  
  169. font-weight: normal;
  170.  
  171.  
  172.  
  173. line-height: 18px;
  174.  
  175.  
  176.  
  177. }
  178.  
  179.  
  180.  
  181. select {
  182.  
  183.  
  184.  
  185. FONT-FAMILY: Tahoma, Arial;
  186.  
  187.  
  188.  
  189. font-size: 11px;
  190.  
  191.  
  192.  
  193. line-height: 18px;
  194.  
  195.  
  196.  
  197. font-weight: normal;
  198.  
  199.  
  200.  
  201. color: #292929;
  202.  
  203.  
  204.  
  205. text-decoration: none;
  206.  
  207.  
  208.  
  209. border: 1px solid #7F9DB9;
  210.  
  211.  
  212.  
  213. }
  214.  
  215.  
  216.  
  217. .select {
  218.  
  219.  
  220.  
  221. FONT-FAMILY: Tahoma, Arial;
  222.  
  223.  
  224.  
  225. font-size: 11px;
  226.  
  227.  
  228.  
  229. line-height: 18px;
  230.  
  231.  
  232.  
  233. font-weight: normal;
  234.  
  235.  
  236.  
  237. color: #292929;
  238.  
  239.  
  240.  
  241. text-decoration: none;
  242.  
  243.  
  244.  
  245. border: 1px solid #7F9DB9;
  246.  
  247.  
  248.  
  249. }
  250.  
  251.  
  252.  
  253. .para {
  254.  
  255. font-family: Tahoma, Arial;
  256.  
  257. font-size: 11px;
  258.  
  259. color: #60656C;
  260.  
  261. line-height: 18px;
  262.  
  263. text-align: justify;
  264.  
  265. font-weight: normal;
  266.  
  267.  
  268.  
  269. }
  270.  
  271.  
  272.  
  273. .bg_body_bottom {
  274.  
  275.  
  276.  
  277. background-image: url(images/body_bottom.jpg);
  278.  
  279.  
  280.  
  281. background-repeat: no-repeat;
  282.  
  283.  
  284.  
  285. background-position: center bottom;
  286.  
  287.  
  288.  
  289. }
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297. input {
  298.  
  299.  
  300.  
  301. FONT-SIZE: 11px;
  302.  
  303.  
  304.  
  305. FONT-FAMILY: Tahoma, Arial;
  306.  
  307.  
  308.  
  309. color: #292929;
  310.  
  311.  
  312.  
  313. border: 1px solid #7F9DB9;
  314.  
  315.  
  316.  
  317. }
  318.  
  319.  
  320.  
  321. .colorbox {
  322.  
  323.  
  324.  
  325. background-color: #FFFFCC;
  326.  
  327.  
  328.  
  329. text-align: justify;
  330.  
  331.  
  332.  
  333. border: 1px solid #CDD6DD;
  334.  
  335.  
  336.  
  337. font-family: Tahoma, Verdana, Arial;
  338.  
  339.  
  340.  
  341. font-size: 11px;
  342.  
  343.  
  344.  
  345. color: #333333;
  346.  
  347.  
  348.  
  349. line-height: 16px;
  350.  
  351.  
  352.  
  353. }
  354.  
  355.  
  356.  
  357. strong {
  358.  
  359.  
  360.  
  361. font-family: Tahoma, Verdana, Arial;
  362.  
  363.  
  364.  
  365. font-size: 11px;
  366.  
  367.  
  368.  
  369. font-weight: bold;
  370.  
  371.  
  372.  
  373. color: #000000;
  374.  
  375.  
  376.  
  377. }
  378.  
  379.  
  380.  
  381. table
  382.  
  383. {
  384.  
  385. border-collapse: separate;
  386.  
  387.  
  388.  
  389. empty-cells: show;
  390.  
  391. }
  392.  
  393.  
  394.  
  395. fieldset{
  396.  
  397. border: 1px solid #7F9DB9;
  398.  
  399.  
  400.  
  401. }
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409. #fieldset1{
  410.  
  411. border: 1px solid #7F9DB9;
  412.  
  413. width: 390px;
  414.  
  415. }
  416.  
  417.  
  418.  
  419. #fieldset2{
  420.  
  421. border: 1px solid #7F9DB9;
  422.  
  423. width: 390px;
  424.  
  425. }
  426.  
  427.  
  428.  
  429. .rightcoldiv h2 {
  430.  
  431. margin: 0 0 5;
  432.  
  433. font-size: 16px;
  434.  
  435. padding: 3px 0px 3px 10px;
  436.  
  437. color: white;
  438.  
  439. padding: 3px 0px 3px 10px;
  440.  
  441. border-bottom-width: 1px;
  442.  
  443. border-bottom-style: solid;
  444.  
  445. border-bottom-color: #e27901;
  446.  
  447. background-color: #1869BD;
  448.  
  449. background-repeat: repeat;
  450.  
  451. }
  452.  
  453.  
  454.  
  455. .bluetext {
  456.  
  457. color: #5584B0;
  458.  
  459. font: menu;
  460.  
  461. font-size: 13px;
  462.  
  463. }
  464.  
  465.  
  466.  
  467. .blueboldtext {
  468.  
  469. color: #5584B0;
  470.  
  471. font: menu;
  472.  
  473. font-size: 13px;
  474.  
  475. font-weight: bold;
  476.  
  477. }
  478.  
  479.  
  480.  
  481. .fontstyle1{
  482.  
  483. font-family: Verdana, Helvetica, Arial;
  484.  
  485. font-size: 9px;
  486.  
  487. font-color: #000000;
  488.  
  489. font-weight: normal;
  490.  
  491. line-height: 11px;
  492.  
  493. text-align: justify;
  494.  
  495. }
  496.  
  497.  
  498.  
  499. .fontheader1{
  500.  
  501. font-family: Verdana, Helvetica, Arial;
  502.  
  503. font-size: 11px;
  504.  
  505. font-color: #000000;
  506.  
  507. font-weight: bold;
  508.  
  509. line-height: 12px;
  510.  
  511. text-align: justify;
  512.  
  513. }
  514.  
  515.  
  516.  
  517. /*----siva-------------*/
  518.  
  519. .table
  520.  
  521. {
  522.  
  523. border-collapse: separate;
  524.  
  525.  
  526.  
  527. empty-cells: show;
  528.  
  529.  
  530.  
  531. /*border: 2px outset #7F9DB9 ;*/
  532.  
  533. }
  534.  
  535.  
  536.  
  537. .tblCardView{
  538.  
  539. border-collapse: separate;
  540.  
  541. empty-cells: show;
  542.  
  543. /*border: 2px outset #7F9DB9 ;*/
  544.  
  545. }
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553. .td{
  554.  
  555. FONT-SIZE: 14px;
  556.  
  557.  
  558.  
  559. FONT-FAMILY: Tahoma, Arial;
  560.  
  561.  
  562.  
  563. color: #000000;
  564.  
  565.  
  566.  
  567. border-color: #ECF9FF;
  568.  
  569.  
  570.  
  571. border-style: ridge;
  572.  
  573.  
  574.  
  575. }
  576.  
  577.  
  578.  
  579. .td1{
  580.  
  581. background-color: #DAE4F0;
  582.  
  583.  
  584.  
  585. border-top: dashed thin black;
  586.  
  587.  
  588.  
  589. border-bottom: dashed thin black;
  590.  
  591.  
  592.  
  593. border-left: dashed thin black;
  594.  
  595.  
  596.  
  597. border-right: dashed thin black;
  598.  
  599. }
  600.  
  601.  
  602.  
  603. .tr1{
  604.  
  605.  
  606.  
  607. background-color: #DAE4F0;
  608.  
  609. border-top: solid thin black;
  610.  
  611. border-bottom: solid thin black;
  612.  
  613. border-left: solid thin black;
  614.  
  615. border-right: solid thin black;
  616.  
  617. }
  618.  
  619.  
  620.  
  621. .tr2{
  622.  
  623. background-color: #C4D3E6;
  624.  
  625. border-top: solid thin black;
  626.  
  627. border-bottom: solid thin black;
  628.  
  629. border-left: solid thin black;
  630.  
  631. border-right: solid thin black;
  632.  
  633. }
  634.  
  635.  
  636.  
  637. .th{
  638.  
  639. background-color: #B0C4DD;
  640.  
  641.  
  642.  
  643. FONT-SIZE: 11px;
  644.  
  645.  
  646.  
  647. FONT-FAMILY: Tahoma, Arial;
  648.  
  649.  
  650.  
  651. color: #000000;
  652.  
  653.  
  654.  
  655. border-color: #ECF9FF;
  656.  
  657.  
  658.  
  659. /*border-style: ridge;*/
  660.  
  661. }
  662.  
  663.  
  664.  
  665. .outerborder{
  666.  
  667. border-top: solid thin;
  668.  
  669. border-bottom: solid thin;
  670.  
  671. border-left: solid thin;
  672.  
  673. border-right: solid thin;
  674.  
  675. }
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683. .tdLabel{
  684.  
  685. text-align: left;
  686.  
  687. width: 40%
  688.  
  689. }
  690.  
  691.  
  692.  
  693. .label{
  694.  
  695. font-family: Arial,Helvetica,sans-serif;
  696.  
  697. font-size: 12px;
  698.  
  699.  
  700.  
  701. }
  702.  
  703.  
  704.  
  705. .boxheading {
  706.  
  707. padding: 5px 0;
  708.  
  709. text-indent: 10px;
  710.  
  711. background: #F7F7F7;
  712.  
  713. /*display: block;*/
  714.  
  715. border-bottom: 1px solid #DDD;
  716.  
  717. color: #4A69A5;
  718.  
  719. text-decoration: none;
  720.  
  721. }
  722.  
  723.  
  724.  
  725. .columnHeading{
  726.  
  727. padding: 5px 0;
  728.  
  729. text-indent: 10px;
  730.  
  731. background: #F7F7F7;
  732.  
  733. /*display: block;*/
  734.  
  735. border-bottom: 1px solid #DDD;
  736.  
  737. color: #4A69A5;
  738.  
  739. text-decoration: none;
  740.  
  741. font-weight: strong;
  742.  
  743. }
  744.  
  745.  
  746.  
  747.  
  748.  
  749. .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
Similar Threads
Reputation Points: 18
Solved Threads: 0
Light Poster
jaiprakash15 is offline Offline
27 posts
since Nov 2008
Apr 22nd, 2009
0

Re: Create HTML file from Dynamic JSP

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.

Java Syntax (Toggle Plain Text)
  1. <%@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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
naugiedoggie is offline Offline
12 posts
since Apr 2009
Apr 22nd, 2009
0

Re: Create HTML file from Dynamic JSP

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..
Reputation Points: 18
Solved Threads: 0
Light Poster
jaiprakash15 is offline Offline
27 posts
since Nov 2008
Apr 22nd, 2009
0

Re: Create HTML file from Dynamic JSP

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

Java Syntax (Toggle Plain Text)
  1. <%@page pageEncoding="UTF-8" info="Gallery"%>
  2.  
  3. <jsp:useBean id="navigation" scope="page" class="org.mistysplace.utility.NavigationBean">
  4. <jsp:setProperty name="navigation" property="pageName" value="<%= this.getServletInfo() %>"></jsp:setProperty>
  5. </jsp:useBean>

This code is called like this:

Java Syntax (Toggle Plain Text)
  1. <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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
naugiedoggie is offline Offline
12 posts
since Apr 2009
Apr 23rd, 2009
0

Re: Create HTML file from Dynamic JSP

THanks for the reply.. Will try with your idea and get back to you..
Reputation Points: 18
Solved Threads: 0
Light Poster
jaiprakash15 is offline Offline
27 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: How to convert the JSP content to PDF file
Next Thread in JSP Forum Timeline: need help in web development





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC