JSP combined with JavaBean to generate a static page sample

Source: Internet
Author: User




 


JSP combines JavaBean to generate a static page sample


1, why to do: Save the cost of operating the database non-stop, reduce the cost of parsing JSP pages


2, how to do: very simple, that is, the use of file operations, the need for the content and ready-made template synthesis and then write a new static web page OK.


3, Function extension: Here just write the file in the way, the combination of HTML content to write to a Web page, but, in order to refer to the page to know that there is the existence of the page, we still have to be in the database or static page to add this information. In order to be simple, you can use the database here, of course, you have to use all static pages can also be a bit more complicated, but if you can fully understand the example, then the other is not a problem.


3.1 file name generation: can be generated in a random way, how to generate a view of personal preferences, can be full number, can also add letters and so on.


3.2 Save the file name and path to the database: So the front desk displays all existing static pages for easy access with one page.


 


4, the following is a simple example:


 


import Java.io.BufferedWriter;


import java.io.File;


import Java.io.FileWriter;


 


publicclass jsptostatichtmltest {


public jsptostatichtmltest () {


    }


String midstr;//such as text in the middle of the article


String filename= "demo.htm";


    /**


* Header string in a template


* @return


     */


Private String getheadstr () {


String s= "<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" n "+


" " "Http://www.w3.org/TR/html4/loose.dtd" >n " +


"<%@ page contenttype=" TEXT/HTML;CHARSET=GBK "%>n" +


"<%@ page import=" palfinger.bean.GetComponentDetailListDependByID_FinishedProduct_add_in "%>n" +


"


"


" <meta http-equiv=" Content-type "content=" text/html; CHARSET=GBK "/>n" +


"<title>jsp plus java</title>n" +


"<script language=" JavaScript1.2 " type=" Text/javascript "src=" Function.js ">n" +


"</script>n" +


"


"<body>n" +


"<center>";


return s;


    }


    /**


* The tail string in a template


* @return


     */


Private String gettailstr () {


String s= "</center>n" +


"</body>n" +


"


return s;


    }


    /**


* The middle is what we need, dynamically generated strings,


* @parammidStr


     */


publicvoid setmidstr (String midstr) {


this.midstr = midstr;


    }


    /**


* Gets the middle dynamically generated string


* @return


     */


Private String getmidstr () {


Returnmidstr;


    }


    /**


* Entire string


* @return


     */


Private String htmlstr () {


String s=getheadstr () +getmidstr () +gettailstr ();


return s;


    }


publicvoid setfilename (String fileName) {


this.filename = fileName;


    }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.