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();
}
}