区分activity的四种加载模式
2015-10-29 14:42
411 查看
public static void generatorHtml() {
String html = "";
String filePath = ServletActionContext.getServletContext().getRealPath(
"/index.html");
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
try {
HttpServletRequest request = ServletActionContext.getRequest();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort();
URL url = new URL(basePath + "/index_doQuery.do");
URLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
uc.setConnectTimeout(3000);
InputStream in = uc.getInputStream();
int n;
StringBuffer buffer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(
in, "utf-8"));
while ((n = reader.read()) != -1) {
buffer.append((char) n);
}
html = new String(buffer.toString());
file.createNewFile();
FileOutputStream o = new FileOutputStream(filePath);
o.write(html.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
}
String html = "";
String filePath = ServletActionContext.getServletContext().getRealPath(
"/index.html");
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
try {
HttpServletRequest request = ServletActionContext.getRequest();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort();
URL url = new URL(basePath + "/index_doQuery.do");
URLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
uc.setConnectTimeout(3000);
InputStream in = uc.getInputStream();
int n;
StringBuffer buffer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(
in, "utf-8"));
while ((n = reader.read()) != -1) {
buffer.append((char) n);
}
html = new String(buffer.toString());
file.createNewFile();
FileOutputStream o = new FileOutputStream(filePath);
o.write(html.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
}
相关文章推荐
- 改变未来IT世界的十种编程语言:Go语言
- Mysql 数据目录的迁移方法
- servlet-mapping元素及其子元素的使用方法
- git 创建分支,删除分支,管理分支
- myBatis批量添加,修改和删除
- 基于MDK平台 cortex-M3 shell 的实现
- AsyncTask源码解析
- Happy Number
- 图解JavaScript中的this关键字
- menuconfig菜单选项
- linux mongodb 安装
- getOutputStream() has already been called for this response 错误异常的处理
- Java编程思想第四版读书笔记——第十一章 持有对象
- bash 快捷键
- Happy Number
- PostgreSQL-pg_dump,pg_restore
- 终于知道10月27-28-29这3天为什么调整了
- 软件安装方式
- 关于log4j的使用
- 已知先序遍历和中序遍历,求后序遍历 && 求二叉树中节点的最大距离