JSP怎么生成静态HTML页面

JSP怎么生成静态HTML页面,在eclipse平台里,用Java代码

3个回答

用servlet的response直接输出html页面代码即可。

public class HTMLMaker { final static Object lock = new Object(); public static void makeHtml(String page, String filePath){ makeHtml(page,filePath,"UTF-8"); } public static void makeHtml(String page, String filePath,String chartset) { synchronized (lock) { HttpURLConnection huc = null; BufferedReader br = null; BufferedWriter bw = null; try { huc = (HttpURLConnection)new URL(page).openConnection(); System.setProperty("sun.net.client.defaultConnectTimeout", "30000"); System.setProperty("sun.net.client.defaultReadTimeout", "30000"); huc.connect(); InputStream stream = huc.getInputStream(); bw = new BufferedWriter(new OutputStreamWriter (new FileOutputStream(filePath),chartset)); br = new BufferedReader(new InputStreamReader(stream, chartset)); String line; while((line = br.readLine())!= null){ if(line.trim().length() > 0){ bw.write(line); bw.newLine(); } } }catch (Exception e) { e.printStackTrace(); }finally { try { br.close(); bw.close(); huc.disconnect(); }catch (Exception e) { e.printStackTrace(); } } } }}

freemaker试试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问