Using Java to generate a static Web page example of a Dynamic Web page _java

Source: Internet
Author: User

Copy Code code as follows:

Package com.tools;
Import java.io.*;
Import Java.net.URL;

/**
* Title: Dynamic page static
*/
public class Gotohtml {
/**
*
* @param page
* Local file path for static pages (C,D,E,F,G)
* @param url_addr
* URL address of the static page to be generated (http://)
* @return
*/
public boolean PrintPage (String page, string url_addr) {

System.out.println ("page" + page);

String newpage = "";
Determines whether the local path entered is in. The end of the JSP
if (Page.endswith (". html")) {

System.out.println ("This are end with xxx.html");
int bias = Page.lastindexof ("/");//bias (meaning of slash) gets the position of the last slash
System.out.println ("The last/at:" + bias);

NewPage = page.substring (0, bias);
System.out.println ("newpage:" + newpage);
}

If the folder does not exist, create a
File FF = new file (newpage);
Ff.mkdirs ();

URL url;
String rline = null;
PrintWriter fileout = null;
InputStream ins = null;
try {
url = new URL (url_addr);
System.out.println (url+ "...");
INS = Url.openstream ();
BufferedReader breader = new BufferedReader (New InputStreamReader (
INS, "Utf-8"))//Get files encoded as gb2312
FileOutputStream out = new FileOutputStream (page);
OutputStreamWriter writer = new OutputStreamWriter (out, "utf-8");
Fileout = new PrintWriter (writer);
Iterates through the data and writes to the destination file
while ((Rline = Breader.readline ())!= null) {
String tmp_rline = rline;
System.out.println (Tmp_rline);
int str_len = Tmp_rline.length ();
if (Str_len > 0) {
Fileout.println (Tmp_rline);
Fileout.flush ();
}
Tmp_rline = null;
}
url = null;
return true;
catch (IOException e) {
System.out.println ("Error:" + e.getmessage ());
E.printstacktrace ();
return false;
catch (Exception es) {
System.out.println (Es.getmessage ());
return false;
finally {//shutdown resource
Fileout.close ();
try {
Ins.close ();
catch (IOException ex) {
Turn off input and outflow error
Ex.printstacktrace ();
}
}

}
public static void Main (string[] args) {

gotohtml gth = new gotohtml ();
String accresstoken= "w67k0vh4k5yph3dpk75jkmechvw_utybtqjd-vb8vxrfd3aovhhk_apjq7jmouhiytsru3_voj2ixrccluab_6- Hblsmxzz_dwqtup3908aoioukkrnxllagh0ac7rnvsazybyxwi8670us-ryd1va ";
String media= "y9kk2wmps4byzxiyfz7_nq6gyi8ev7-hyzg5hbadkoqoblfs9jit8_x2s4zovc1g";
String urlstring= "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" +accresstoken+ "&media_id=" + Media
Gth. PrintPage ("d:/eclipse/newnum.html", "http://localhost/prime/user/userFind_update.jsp?id=93");
Gth. PrintPage ("d:/newnum.html", urlstring);
}
}

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.