JSPÉú³É¾²Ì¬Ò³Ãæ
JDK 1.5 +ECLIPSE +TOMCAT 5.0.28 + MYSQL 5.0
Êý¾Ý¿âTEST¡¡£¬±íÃûnews
×ֶΣº¡¡id int ×Ô¶¯Ôö³¤¡¡, Title varchar(20) , Content varchar(200) , Author varchar(10)
makeFile.jsp
<%
Connection conn = DBconn.getConnection();
Statement stmt = conn.createStatement();
ResultSet Rs = stmt.executeQuery("select * from news");
System.out.println("success");
%>
<%
String filePath = request.getRealPath("/")+"template.htm";
System.out.println(filePath);
String templateContent;
FileInputStream fileinputstream = new FileInputStream(filePath);
int lenght = fileinputstream.available(); //available() ·µ»Ø¿ÉÒÔ²»ÊÜ×èÈûµØ´Ó´ËÎļþÊäÈëÁ÷ÖжÁÈ¡µÄ×Ö½ÚÊý¡£
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes); //read(byte[] b) ´Ó´ËÊäÈëÁ÷Öн«×î¶à b.length ¸ö×Ö½ÚµÄÊý¾Ý¶ÁÈëÒ»¸ö×Ö½ÚÊý×éÖС£
fileinputstream.close();
//templateContent = new String(bytes);
String title;
String content;
String author;
while(Rs.next())
{
templateContent = new String(bytes);//Èç¹û²»ÓÃÕâ¾ä£¬ÔòÌæ»»Ò»´ÎÖ®ºó£¬templateContentÖоÍûÓÐ#**#±êÖ¾ÁË¡£ËùÒÔÒªÖØÐÂÉú³É
title = Rs.getString("Title");
content = Rs.getString("Content");
author = Rs.getString("Author");
out.println(title+"********"+content+"****"+author);
out.print("ÒÔÏÂÊÇÄ£°åÄÚÈÝ£º<br>"+templateContent+"<br> ÒÔÏÂÊÇÖû»ÒÔºóµÄhtmlÄÚÈÝ<br><hr>");
templateContent=templateContent.replaceAll("#title#",title);
templateContent=templateContent.replaceAll("#author#",author);//Ìæ»»µôÄ£¿éÖÐÏàÓ¦µÄµØ·½
templateContent=templateContent.replaceAll("#content#",content);
// ¸ù¾Ýʱ¼äµÃÎļþÃû
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis()) +".html";
fileame = request.getRealPath("/")+"Html/"+fileame;//Éú³ÉµÄhtmlÎļþ±£´æÂ·¾¶
out.print(
Ïà¹ØÎĵµ£º
ʲôÊÇ×Ô¶¨Òå±êÇ©£¿
1£¬Óû§×Ô¶¨ÒåµÄJavaÓïÑÔÔªËØ, ʵÖÊÊÇÔËÐÐÒ»¸ö»òÕßÁ½¸ö½Ó¿ÚµÄJavaBean;
2£¬¿ÉÒԷdz£½ôÃܵغÍJSPµÄ±íʾÂß¼ÁªÏµÔÚÒ»Æð£¬ÓÖ¾ßÓÐºÍÆÕͨJavaBeanÏàͬµÄÒµÎñÂß¼´¦ÀíÄÜÁ¦;
3£¬µ±Ò»¸öJSPÒ³Ãæ×ª±äΪservletʱ£¬Æä¼äµÄÓû§×Ô¶¨Òå±êǩת»¯Îª²Ù×÷Ò»¸ö³ÆÎª±êÇ©handerµÄ¶ÔÏó;
4£¬¿É²Ù×÷ĬÈ϶ÔÏ󣬴¦Àí±íµ¥Êý¾Ý£¬ ......
1 1 Linux Red Hat 7.2 °²×°
¡¡¡¡Red Hat Linux 7.2µÄ°²×°¹âÅ̹²ÓÐÁ½ÕÅ£ºµÚÒ»ÕÅ¿ÉÒÔÖ±½Ó´Ó¹âÅÌÆô¶¯£¬°üº¬Á˴󲿷ֵÄÈí¼þ°üºÍһЩ°²×°¹¤¾ß£»µÚ¶þÕŹâÅ̳ýÁ˸½¼ÓµÄÈí¼þ°üÍ⣬Ö÷ÒªÊÇÔ´Âë¡¢Ô¤ÀÀ°æÈí¼þµÈ¡£
¡¡¡¡Red Hat Linux 7.2µÄ°²×°½çÃæ·Ç³£ÓѺã¬×óÃæÓм´Ê±Ï꾡µÄ°ïÖúÐÅÏ¢£¬ÓÒÃæÊÇÑ¡ÏÍêȫ֧³ÖÊó±ê²Ù×÷¡£
¡¡¡¡½« ......
ÎÒÃǶ¼ÖªµÀÔÚjspÖÐincludeÓÐÁ½ÖÖÐÎʽ,·Ö±ðÊÇ
< %@ include file=” ”%>
< jsp:include page=” ” flush=”true”/>
¡¡¡¡Ç°ÕßÊÇÖ¸ÁîÔªËØ¡¢ºóÕßÊÇÐÐÎªÔªËØ¡£¾ßÌåËüÃǽ«Ôںδ¦Óã¿ÈçºÎÓü°ËüÃÇÓÐÊ²Ã´Çø±ð£¿ÕâÓ¦¸ÃÊǺܶàÈË¿´µ½Ëü¶¼»áÏëµ½µÄÎÊÌâ¡£ÏÂÃæÒ»ÆðÀ´¿´¿´°É¡£
¡ ......
1,Ò³ÃæÉϱàÂëÉèÖÃΪ"UTF-8"
2,дһ¸ö×Ö·û±àÂë¹ýÂËÆ÷, ÔÚweb.xmlÖÐÅäÖüÓÔØ¹ýÂËÆ÷
3,ÉèÖÃtomcatµÄÊôÐÔ ÔÚÅäÖö˿ڵĽڵãÉϼÓÈëÈçÏ´úÂë:URIEncoding="UTF-8"
1,´úÂëÈçÏÂ:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2,ʵÏÖ´úÂë:
package com.mww.comm;
import java.io. ......