?1
LeaveWord.jsp
?2
..
?3
<
div?
class
=
"
NewContent
"
>
?4
<
label
>
留言表情
</
label
>
?5
<
table
>
?6
<
tr
>
?7
<
td
></
td
>
?8
<
td?style
=
"
WORD-BREAK:?break-all
"
>
?9
<%
10
?????
//
需要讀取的文件絕對路徑:?G:\JavaStudio\Tomcat5\webapps\Home\BatGuestBook\BatFace
11
?????String?picFile?
=
?request.getRealPath(
"
/
"
)
+
?
"
BatGuestBook\\BatFace\\
"
;?????
12
????
13
?????
/**/
/*
???request.getRealPath("/")??結果=?G:\JavaStudio\Tomcat5\webapps\Home\
14
??????*???該LeaveWord.jsp文件放在?BatGuestBook?目錄下(圖片存放在BatGuestBook?\BatFace下)
15
??????*???加上這個?"BatGuestBook\\BatFace\\"?表示得到了圖片目錄.
16
??????
*/
17
?????File?pictures?
=
?
new
?File(picFile);???????
//
建立該圖片文件對象
18
?????String?list[]?
=
?pictures.list();????????????
//
取得該文件下的所有文件
19
?????
for
?(
int
?i
=
0
;?i
<
list.length;?i
++
)
{??????
//
對文件進行過濾
20
?????????
if
?(list[i].toLowerCase().endsWith(
"
jpg
"
)?
||
?list[i].toLowerCase().endsWith(
"
jpeg
"
)??
||
??list[i].toLowerCase().endsWith(
"
gif
"
)?
||
?list[i].toLowerCase().endsWith(
"
bmp
"
)?
||
??list[i].toLowerCase().endsWith(
"
png
"
)?)
{
21
????????
{????
22
????????????ist[i]??
=
?
"
BatFace\\
"
+
?list[i];
23
????????????
//
結果:?BatFace\01.gif?
..?BatFace\20.gif
24
?
%>
25
<
INPUT?type
=
"
radio
"
?value
=<%=
i
%>
?name
=
"
face
"
?checked
>
26
<
img?src
=
"
<%=list[i]%>
"
?alt
=
"
<%=list[i]%>
"
?
/>
27
<%
?}
28
???}
29
?}
30
%>
31
</
td
>
32
</
tr
>
33
</
table
>
34
</
div
>
????
35
..
36
/
?/*
???總結?:這樣基本解決了在不同機子上讀取文件下的圖片的問題
??*???但是,?要是圖片文件改名字那就不行了?,不知道各位是否有更好的方法?
??*???有何想法和看法?歡迎交流、賜教!!!
? *???Date:2006-4-23??Author:blackbat??(轉載請注明出處?
http://m.tkk7.com/blackbat/
)
? */