General static website Solution

Source: Internet
Author: User

Read and Write of multiple file servers. SMB protocol can be used here.
Static Page, use freemarker open-source framework
If a large number of read/write requests are taken into account, the requests are distributed or scheduled.
First, we should consider the ing between the file server and the static page, that is, the server to which the file should be read and written. The simplest way to do this is random ing, then save the ing to the database. The common SMB operation code is as follows:
Copy codeThe Code is as follows:
Public static boolean exists (String filepath, String username, String pwd) throws Exception
{
SmbFile file = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
Try {
Return file. exists ();
} Catch (Exception ex ){
Return false;
}
}

Public static boolean fileRename (String filepath, String newFilename, String username, String pwd)
{
Try {
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
If (f. isFile ()){
String str = filepath. substring (0, filepath. lastIndexOf ("/"));
Str = "smb: //" + username + ":" + pwd + "@" + str + "/" + newFilename;
F. renameTo (new SmbFile (str ));
} Else if (f. isDirectory ()){
String str = filepath. substring (0, filepath. length ()-1 );
Str = filepath. substring (0, str. lastIndexOf ("/"));
Str = "smb: //" + username + ":" + pwd + "@" + str + "/" + newFilename;
F. renameTo (new SmbFile (str ));
}
Return true;
} Catch (Exception ex ){
Return false;
}
}

Public static void mkdir (String dir, String username, String pwd)
{
Try {
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + dir );
If (! F. exists ())
F. mkdir ();
} Catch (Exception ex)
{
}
}

Public static void mkfile (String filepath, String username, String pwd)
{
Try
{
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
If (! F. exists ())
F. createNewFile ();
} Catch (Exception ex)
{
}
}

Public static void mkfile (String filepath, String username, String pwd, String content)
{
Try
{
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
If (! F. exists ())
F. createNewFile ();
WriteFile (filepath, content, username, pwd );
} Catch (Exception ex)
{
}
}

Public static boolean isdir (String filepath, String username, String pwd) throws Exception
{
String dir = "smb: //" + username + ":" + pwd + "@" + filepath;
SmbFile f = new SmbFile (dir );
Return f. isDirectory ();
}

Second, static pages can be generated by freemarker. The use of freemarker is relatively simple. I will not say it again.
Third, the scheduling center, or the static request is saved to the Task first, and then executed asynchronously through the scheduling center, which can be solved by another article I mentioned in my blog.

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.