JSP is used to generate static news pages (1). It also talks about the technology of using JSP to implement groom and Sohu news systems.

Source: Internet
Author: User

(Unlike generating static html from JSP, all the news is static.

If the HTM template is used, it will be replaced in different places.

)

Similar;

<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" errorpage = "" %>
<% @ Page import = "Java. util. *, java. Io. *" %>
<% @ Include file = "../INC/includebean. jsp" %>
<%
Request. setcharacterencoding ("UTF-8 ");
String title = request. getparameter ("newstitle ");
String newsfrom = request. getparameter ("newsfrom ");
String DOCT = request. getparameter ("newsdoct ");
String fileame = "";
Int A = 0;
Try {
String filepath = "", Path = "";
Filepath = request. getrealpath ("/") + "News/modle.html ";
Filepath = filepath. replaceall ("////","/");
String templatecontent = "";
 
// Read the hmtl Template File
Fileinputstream FCM = new fileinputstream (filepath );
Stringbuffer content = new stringbuffer ();
Datainputstream in = new datainputstream (FCM );
Bufferedreader BR = new bufferedreader (New inputstreamreader (in, "UTF-8 "));
String line = NULL;
While (line = Br. Readline ())! = NULL)
Content. append (LINE + "/N ");
BR. Close ();
In. Close ();
FCM. Close ();
 
// Replace the relevant part of the template
Templatecontent = new string (content );
Templatecontent = templatecontent. replaceall ("### title ###", title );
Templatecontent = templatecontent. replaceall ("### source ###", newsfrom );
Templatecontent = templatecontent. replaceall ("### addtime ###", nowtime );
Templatecontent = templatecontent. replaceall ("### Article ###", DOCT); // replace the corresponding content in the module
Calendar calendar = calendar. getinstance ();
Fileame = string. valueof (calendar. gettimeinmillis () + ". html ";
 
// Create a news page storage directory
Path = request. getrealpath ("/") + "News/" + nowtime + "/";
File d = new file (PATH); // create a file object that represents the sub directory and obtain a reference
If (! D. exists () {// check whether the sub directory exists
D. mkdir (); // create a sub directory
}
File F = new file (path, fileame );
If (! F. exists () {// check whether file.txt exists
F. createnewfile (); // create a file named file.txt in the current directory.
}
Fileame = request. getrealpath ("/") + "News/" + nowtime + "/" + fileame; // save path of the generated HTML file

// Write the replaced content to the file
Fileoutputstream Fos = new fileoutputstream (fileame );
Writer output = new outputstreamwriter (FOS, "UTF-8 ");
Output. Write (templatecontent );
Output. Close ();
FOS. Close ();
 
} Catch (exception e ){
System. Out. Print (E. tostring ());
}
%>

2. The database saves the file title, file name, date, and other information at the same time, and there is no need to retain other information such as news content;
3rd. You can directly retrieve the xxx.htm file name and file title from the data warehouse;

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.