Java 常用工具类(16) : jsp和thymeleaf及其他模板页面静态化工具类
2018-04-03 10:21
666 查看
import java.io.File; import java.io.FileWriter; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; /** * 页面静态化 * @author guyinyihun * */ public class StaticizeUtil { public static void jspIndexToStatic() { try { HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod("http://127.0.0.1:9090/"); //首页访问路径 String path=StaticizeUtil.class.getClassLoader().getResource("").getPath(); String path2 = path.replace("/target/classes/", "/src/main/webapp/static/"); client.executeMethod(getMethod); File file = new File(path2+"index.html");//存到webapp的static目录下 FileWriter writer = new FileWriter(file); writer.write(getMethod.getResponseBodyAsString()); writer.flush(); System.err.println("首页静态化已完成..."); } catch (Exception e) { e.printStackTrace(); } } public static void thyIndexToStatic() { try { HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod("http://127.0.0.1:9004/");//首页访问路径 String path=StaticizeUtil.class.getClassLoader().getResource("").getPath(); String path2 = path.replace("/target/classes/", "/src/main/resources/templates/"); client.executeMethod(getMethod); File file = new File(path2+"index.html");//存到/src/main/resources/templates 下 FileWriter writer = new FileWriter(file); writer.write(getMethod.getResponseBodyAsString()); writer.flush(); System.err.println("首页静态化已完成..."); } catch (Exception e) { e.printStackTrace(); } } }
需引入依赖
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1-rc1</version>
</dependency>
相关文章推荐
- springboot 常用两种图形形式(thymeleaf模板,jsp页面)
- Java 常用工具类(16) : BigDecimal加减乘除工具类
- 19-集合框架工具类-16-常用对象API(集合框架-工具类-Collections-其他方法&将非同步集合转成同步集合的方法)
- 【开发工具】Eclipse编写Java/JS/Web/JSP页面智能提示
- Java使用JSP Tag Files & JSP EL Functions打造你自己的页面模板
- java中常用的工具类(三)连接数据库的综合类,DES加密和解密,Base64,ExcelUtil工具类,
- Java工作利器之常用工具类(一)——数字工具类-数字转汉字
- java中常用的工具类(二)FtpUtil, 汉字转拼音,zip工具类,CollectionUtil,MathUtil,
- 16-常用对象API(集合框架-工具类-Collections-其他方法&将非同步集合转成同步集合的方法) 17-常用对象API(集合框架-工具类-Arrays-方法介绍)_20171202
- Java 常用工具类(8) : MD5加密工具类
- java中常用的工具类(一)MD5,File工具类,String工具类
- Java 常用工具类(11) : UUID生成工具类
- jsp 页面静态化 java.net.MalformedURLException: no protocol: index.jsp和java.net.MalformedURLException: unknown protocol: d
- 最全面的Java字节byte操作,处理Java基本数据的转换及进制转换操作工具,流媒体及java底层开发项目常用工具类
- 修改MyEclipse开发工具中的页面模板(JSP和HTML)
- Java工作利器之常用工具类(四)——Json工具类,使用正则支持xml与json互转
- Java 常用工具类(2) : 提取汉字首字母工具类
- java中常用的工具类(三)连接数据库的综合类,DES加密和解密,Base64,ExcelUtil工具类,
- eclipse for javaEE - 新建jsp页面模板设置
- java字符操作获取汉字的拼音以及其他常用工具