您的位置:首页 > 编程语言 > Java开发

[学习笔记]jsp+javaBean 播放幻灯片的小例子

2008-03-30 21:13 483 查看


这个例子实现以上图片的功能

创建Bean的源文件:

PlaySlide.java

package cn.java;

import java.io.*;

public class PlaySlide {
int count=0,max;
String pictureName[],playNext,playPrevious;
public PlaySlide(){
File dir = new File("F://apache-tomcat-5.5.20//apache-tomcat-5.5.20//webapps//long//image");
//图片路径
pictureName=dir.list();
max=pictureName.length;

}
/**
* 上一张按钮的功能实现方法
* */
public String getPlayNext(){
playNext=new String("<image src=image/"+pictureName[count%max]+" width=120 height=100></image>");
count++;
if(count>max){
count=1;
}

return playNext;
}
/**
* 下一张按钮的功能实现方法
* */
public String getPlayPrevious(){
playPrevious=new String("<image src=image/"+pictureName[count%max]+" width=120 height=100></image>");
count--;
if(count<0){
count=max+1;
}

return playPrevious;
}

}

play.jsp

<%@page contentType="text/html;Charset=gb2312"%>
<%@page import="cn.java.PlaySlide"%>
<jsp:useBean id="play" class="cn.java.PlaySlide" scope="session"/>
<html><h4>单击“上一张”或“下一张”按钮观看幻灯片
<body><font size=3>
<form action="" method="post">
<br>
<input type=submit name="ok" value="上一张">
<input type=submit name="ok" value="下一张">
</form>
<%
String str=request.getParameter("ok");
if(str==null){
str="上一张";
}
if(str.equals("上一张")){
%>

<jsp:getProperty name="play" property="playPrevious"/>

<%
}
if(str.equals("下一张")){
%>

<jsp:getProperty name="play" property="playNext"/>
<%
}
%>
</font></body></html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: