/*
* ur 指向jsp的路劲
* request requst对象
* id 公司的id 根据公司ID来创建文件夹
* htmlName 生成的html名字
*/
public static void createHtml(String ur,HttpServletRequest request,int id,String htmlName){
try {
URL url = new URL(ur);
URLConnection urlConnection = url.openConnection();
urlConnection.setConnectTimeout(6000);
urlConnection.setReadTimeout(6000);
String type = urlConnection.getContentType();
// System.out.println(type);
urlConnection.connect();
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
int httpResult = httpURLConnection.getResponseCode();
if (httpResult != HttpURLConnection.HTTP_OK) {
System.out.println("连接失败!路劲错误!");
} else {
System.out.println("连接成功!");
// int contentLength = urlConnection.getContentLength();
// if(contentLength > 0) {
InputStream raw = urlConnection.getInputStream();
InputStream in = new BufferedInputStream(raw);
byte[] data = new byte[100000];
int bytesRead = 0;
int offset = 0;
while(offset < 1000) {
bytesRead = in.read(data, offset, data.length - offset);
if(bytesRead == -1) {
break;
}
offset += bytesRead;
}
in.close();
raw.close();
String str = new String(data, type.split("charset=")[1]);
String fp = request.getSession().getServletContext().getRealPath("/")+"html\\"+id;
File f = new File(fp);
if(!f.exists()){
f.mkdir();
}
String fpp = fp+"\\"+htmlName+".html";
f = new File(fpp);
if(f.exists()){
f.delete();
}
f.createNewFile();
FileWriter fw = null;
fw = new FileWriter(f);
RandomAccessFile mm = null;
mm = new RandomAccessFile(f, "rws");
mm.write(str.getBytes("utf-8"));
mm.close();
System.out.println(htmlName+".html生成成功");
}
// }
}catch(Exception e) {
System.out.println(htmlName+".html生成失败!");
}
}
* ur 指向jsp的路劲
* request requst对象
* id 公司的id 根据公司ID来创建文件夹
* htmlName 生成的html名字
*/
public static void createHtml(String ur,HttpServletRequest request,int id,String htmlName){
try {
URL url = new URL(ur);
URLConnection urlConnection = url.openConnection();
urlConnection.setConnectTimeout(6000);
urlConnection.setReadTimeout(6000);
String type = urlConnection.getContentType();
// System.out.println(type);
urlConnection.connect();
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
int httpResult = httpURLConnection.getResponseCode();
if (httpResult != HttpURLConnection.HTTP_OK) {
System.out.println("连接失败!路劲错误!");
} else {
System.out.println("连接成功!");
// int contentLength = urlConnection.getContentLength();
// if(contentLength > 0) {
InputStream raw = urlConnection.getInputStream();
InputStream in = new BufferedInputStream(raw);
byte[] data = new byte[100000];
int bytesRead = 0;
int offset = 0;
while(offset < 1000) {
bytesRead = in.read(data, offset, data.length - offset);
if(bytesRead == -1) {
break;
}
offset += bytesRead;
}
in.close();
raw.close();
String str = new String(data, type.split("charset=")[1]);
String fp = request.getSession().getServletContext().getRealPath("/")+"html\\"+id;
File f = new File(fp);
if(!f.exists()){
f.mkdir();
}
String fpp = fp+"\\"+htmlName+".html";
f = new File(fpp);
if(f.exists()){
f.delete();
}
f.createNewFile();
FileWriter fw = null;
fw = new FileWriter(f);
RandomAccessFile mm = null;
mm = new RandomAccessFile(f, "rws");
mm.write(str.getBytes("utf-8"));
mm.close();
System.out.println(htmlName+".html生成成功");
}
// }
}catch(Exception e) {
System.out.println(htmlName+".html生成失败!");
}
}