日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

JSP初級教程之跟我學JSP(六)(4)_JSP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:JSP初級教程之跟我學JSP(五)
第五章 jsp 分頁功能的實現 經過上面的學習我漸漸熟悉了對 數據庫 的操作,留言板的功能也不斷的完善,隨著留言的增加信息的目錄越來越長了,現在需要實現一個分頁功能了,我嘗試自己解決這個問題。 1、我應該把它的關鍵部分封裝成一個bean,使它盡可能的能


int num=Datas.length;//數組的長度
//得此數組中的最大值
int max=Datas[0];
for (int j=0;j<num;j++)
{
if(Datas[j]>max)
max=Datas[j];
}

int imageWidth = 400;//圖片的寬度 Line
int imageHeight;//不定長

int frameFirstWidth=imageWidth-10;
int frameFirstHeight=25;

int frameSecondWidth=imageWidth-10;
int frameSecondHeight;//不定長

int frameSpace=10;//兩框間隔

int columnHeight=18;//柱的粗 
int columnMaxWidth=frameSecondWidth-20;//柱的最大長度,也是代表數值最大的那個柱的長度

int sp=30;//柱的間隔

//得到代表數值的柱的各自高度,實際數值*columnMaxHeight/max
int columnWidth[]=new int[num];//不定長,柱的長度
for (int k=0;k<num;k++)
columnWidth[k]=(Datas[k]*columnMaxWidth)/max;//取整

frameSecondHeight=(sp+columnHeight)*num+10;//+10為了留出一塊底邊
imageHeight=frameSecondHeight+frameFirstHeight+frameSpace+10;//多加10為了畫陰影

//開始畫圖
response.setContentType("image/jpeg");
BufferedImage image = new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_RGB); 
Graphics g = image.createGraphics();

g.setColor(Color.white);
g.fillRect(0,0,imageWidth,imageHeight);//用白色涂整個圖
Color frameFirstColor = new Color(20,50,100);
Color columnColor = new Color(153,19,19);
Color shadowColor = new Color(200,200,200);
g.setColor(shadowColor);
g.fillRect(0+7,0+7,frameFirstWidth,frameFirstHeight);//陰影在原框基礎上移7
g.setColor(Color.white);
g.drawRect(0,0,frameFirstWidth,frameFirstHeight);//畫第一個框
g.setColor(frameFirstColor);
g.fillRect(0+1,0+1,frameFirstWidth-1,frameFirstHeight-1);
g.setFont(new Font("仿體", 0 , 14));
g.setColor(Color.white);
g.drawString(Title,10,18);//寫字
g.drawString(SStr,300,18);

int frameSecondY=1+frameFirstHeight+frameSpace;
g.setColor(shadowColor);
g.fillRect(0+7,frameSecondY+7,frameSecondWidth,frameSecondHeight);//陰影在原框基礎上移7
g.setColor(Color.black);
g.drawRect(0,frameSecondY,frameSecondWidth,frameSecondHeight);//畫第二個框
g.setColor(Color.yellow);
g.fillRect(0+1,frameSecondY+1,frameSecondWidth-1,frameSecondHeight-1);//填充第二個框

for(int l=0;l<num;l++)
{
g.setColor(Color.black);
int textY=frameSecondY+20+(sp+columnHeight)*l;
g.drawString(name[l]+"("+Datas[l]+")",0+10,textY);//寫文字
if (columnWidth[l]!=0)
{
g.setColor(columnColor);
g.drawRect(10,textY+5,columnWidth[l],columnHeight);//畫柱的外框//框的上邊離文字的底邊為5
g.fillRect(10+2,textY+5+2,columnWidth[l]-3,columnHeight-3);//畫柱
}
}
try
{
//輸出圖
OutputStream output = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(image);
output.close();
}
catch(Exception e)

e.printStackTrace();

}//if
else
{%>
<table width="100%">
<tr>
<td width="407">
<span class="style2"><font color="#FF0000">沒有<%=year%>年的記錄!</font></span>
</td>
</tr>
</table>
<%
}
%> 
</body>
</html>
----------------------------------------------------------------------------------
現在任務是完成了,其中的最關鍵的部分代碼是實現什么功能的也大概知道了,可是還是沒有掌握其中的知識,不能不說是遺憾。

有一個問題是,worklord.jsp這樣的頁面很特殊,就是因為這部分代碼引起的:
OutputStream output = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(image);
這導致了這個頁面沒法再干別的了,假如你要在<body>里干點別的,像寫幾個字,放一個<form>什么的,頁面顯示不出來。

分享:JSP初級教程之跟我學JSP(四)
第四章我的第一個 Javabean 程序 一、先看看如何取當前時間并顯示的代碼: ------------------------------------------------ % java.text.SimpleDateFormatformatter=newjava.text.SimpleDateFormat(yyyy-MM-ddHH:mm:ss); java.util.DatecurrentTime=ne

共4頁上一頁1234下一頁
來源:模板無憂//所屬分類:JSP教程/更新時間:2010-03-10
相關JSP教程