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(
Ïà¹ØÎĵµ£º
Jsp ELÓï·¨
Àý£º
${sessionScope.user.sex}
ËùÓÐEL¶¼ÊÇÒÔ ${ ΪÆðʼ¡¢ÒÔ} Ϊ½áβµÄ¡£
ÉÏÊöEL·¶ÀýµÄÒâ˼ÊÇ£º´ÓSessionÈ¡µÃÓû§µÄÐÔ±ð¡£Èç¹ûʹÓÃ֮ǰJSP´úÂëµÄд·¨ÈçÏ£º
<%
User user = (User)session.getAttribute(”user”);
String sex = user.getSex( );
%>
Á½ÕßÏà±È½Ï֮ϣ¬¿ÉÒÔ·¢ÏÖELµÄÓï·¨± ......
ÉÏ¿ÎÀÏʦ½²½âÁËjsp·ÖÒ³ £¬¹ØÓÚ¼ÆËã×ÜÒ³Êý
ËûµÄËã·¨ÊÇ totalPage=(totalRecords+pageSize-1)/pageSize; Ëû˵Èç¹û²»ºÃÀí½â£¬¾ÍÓà i f else Åжϡ£
Ï¿ο´Êé
żȻÏëÆðÁËÒÔǰ£¬µÄÒ»¸öËã·¨
totalPage=(totalRecords%pageSize==0)? (totalRecords/page ......
1 1 Linux Red Hat 7.2 °²×°
¡¡¡¡Red Hat Linux 7.2µÄ°²×°¹âÅ̹²ÓÐÁ½ÕÅ£ºµÚÒ»ÕÅ¿ÉÒÔÖ±½Ó´Ó¹âÅÌÆô¶¯£¬°üº¬Á˴󲿷ֵÄÈí¼þ°üºÍһЩ°²×°¹¤¾ß£»µÚ¶þÕŹâÅ̳ýÁ˸½¼ÓµÄÈí¼þ°üÍ⣬Ö÷ÒªÊÇÔ´Âë¡¢Ô¤ÀÀ°æÈí¼þµÈ¡£
¡¡¡¡Red Hat Linux 7.2µÄ°²×°½çÃæ·Ç³£ÓѺã¬×óÃæÓм´Ê±Ï꾡µÄ°ïÖúÐÅÏ¢£¬ÓÒÃæÊÇÑ¡ÏÍêȫ֧³ÖÊó±ê²Ù×÷¡£
¡¡¡¡½« ......
ËÄ£®ÇúÏßͼ
½Ó×ÅÎÒÃÇÀ´½éÉÜÇúÏßͼµÄʹÓá£ÔÚ±ÊÕßÈÕ³£µÄ¿ª·¢¹¤×÷ÖУ¬ÇúÏßͼÓõÃ×î¶à£¬Ëü¿ÉÒÔÓÃÀ´»æÖÆÇ÷ÊÆÍ¼¡¢Í³¼Æ·ÖÎöµÈ¡£Ê×ÏÈÎÒÃÇÔÚWebRootϽ¨Á¢Ò»¸ölineĿ¼£¬ÓÃÀ´´æ·ÅÇúÏßͼʵÀýµÄjspÒ³Ãæ¡£ÎÒÃÇÔÚ¸ÃĿ¼Ï½¨Á¢sample1.jspÒ³ÃæÀ´×öÒ»¸ö¼òµ¥µÄÇúÏßͼµÄÀý×Ó¡£ÔÚ¿ªÊ¼±àÂëǰ£¬ÈÃÎÒÃÇÀ´¿´¿´Óë»ÇúÏßͼÃÜÇÐÏà¹ØµÄ¼¸¸öÀࣺ
1£© ......
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.net.URL"%>
<%
URL url = new URL("http://www.itpub.net");//½¨Á¢URL¶ÔÏ󣬲¢ÊµÀý»¯Îªurl£¬»ñµÃҪץȡµÄÍøÒ³µØÖ·
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(),"GB2312")); ......