import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class sthtml extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GB2312");
String fpath = this.getServletContext().getRealPath("/");// 获得服务器绝对路径
String templateContent = null;
FileInputStream fileinputstream = new FileInputStream(fpath + "mb.html");// 读取模板页,位于网站根目录
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
templateContent = templateContent.replaceAll("#a#", "转换dewr1");
templateContent = templateContent.replaceAll("#b#", "CC.;['");
FileOutputStream fileoutputstream = new FileOutputStream(fpath
+ "ok.html");
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
}
java如何实静态页面 java静态页面生成技术
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章