서버에 대한 부담을 줄이기 위해 원래 기사 관리 시스템은 JSP 파일을 통해 데이터베이스에서 데이터를 가져오는 방식에서 jsp를 통해 정적 HTML 파일을 생성한 후 html 파일에 직접 액세스하는 방식으로 변경되었습니다. 다음은 간단한 예입니다.
1.buildhtml.jsp
<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
노력하다{
문자열 제목="제목입니다";
String content="콘텐츠 영역입니다";
문자열 편집기="라오마오";
문자열 파일 경로 = "";
filePath = request.getRealPath("/")+"test/template.htm";
//out.print(filePath+"<br>");
문자열 templateContent="";
FileInputStream fileinputstream = new FileInputStream(filePath);//모듈 파일 읽기
int 길이 = fileinputstream.available();
바이트 바이트[] = 새 바이트[길이];
fileinputstream.read(바이트);
fileinputstream.close();
templateContent = new String(bytes);
//out.print(templateContent);
templateContent=templateContent.replaceAll("###title###",title);
templateContent=templateContent.replaceAll("###content###",content);
templateContent=templateContent.replaceAll("###author###",editer);//모듈에서 해당 위치를 교체합니다.
//out.print(templateContent);
// 시간을 기준으로 파일 이름을 가져옵니다.
달력 달력 = Calendar.getInstance();
문자열 파일 이름 = String.valueOf(calendar.getTimeInMillis()) +".html";
fileame = request.getRealPath("/")+fileame;//생성된 html 파일 저장 경로
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//파일 출력 스트림 생성
바이트 tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
catch(예외 e){
out.print(e.toString());
}
%>
2. template.htm
<html>
<머리>
<제목>###제목###</제목>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="../css.css" rel=stylesheet type=text/css>
</head>
<본문>
<table width="500" border="0" align="center" cellpadding="0" cellpacing="2">
<tr>
<td align="center">###title###</td>
</tr>
<tr>
<td align="center">저자:###author### </td>
</tr>
<tr>
<td>###내용###
</td>
</tr>
</테이블>
</body>
</html>