image 目录有01.jpg 02.jpg 03.jpg
首先我门看页面
/js
STRUTS
VO
首先我门看页面
<%@ page language="java" pageEncoding="gbk"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<title>index.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath()%>/test/js/indexPic.js"></script>
<SCRIPT type=text/javascript>
function initWin() {
document.getElementById("indexPic").innerHTML=getIndexPic(${list});
}
</SCRIPT>
</head>
<body onload="initWin();">
<div id="indexPic"></div>
</body>
</html:html>
/js
function getIndexPic(inforList) {
var maxPic=10;
var imgUrl=[];
var imgLink=[];
var imgText=[];
var j=0;
for(var i=0; i<inforList.length && i<maxPic; i++) {
var article=inforList[i];
//alert(article.indexPic);
if(article.indexPic!=null && article.indexPic!="") {
imgUrl[j]="./image/"+article.indexPic;
imgLink[j]="../test";
imgText[j]="123"
//alert(getProperty("plateName",article.plate));
j++;
}
}
var focus_width=270;
var focus_height=200;
var text_height=20;
var swf_height = focus_height+text_height;
//j= maxPic ? imgUrl.length : imgUrl.length>maxPic;
//alert("长度:"+imgUrl.length+"");
var pics="";
var links="";
var texts="";
for (var i=0;i<imgUrl.length;i++) {
pics=pics+imgUrl[i]
if( (i<imgUrl.length-1)) {pics=pics+"|";}
links=links+imgLink[i]
if( (i<imgUrl.length-1)) {links=links+"|";}
texts=texts+imgText[i]
if( (i<imgUrl.length-1)) {texts=texts+"|";}
}
alert(pics);
alert(links);
alert(texts);
var rusult=
'<table border="0" width="100%" cellspacing="0" cellpadding="0" height="235" align="center">'
+'<tr>'
+'<td height="1"></td>'
+'</tr>'
+'<tr>'
+'<td height="211">'
+'<p align="center">'
+'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">'
+'<param name="allowScriptAccess" value="sameDomain">'
+'<param name="movie" value="./flash/article/indexPic.swf">'
+'<param name="quality" value="high">'
+'<param name="bgcolor" value="#dfdfdf">'
+'<param name="menu" value="false">'
+'<param name=wmode value="opaque">'
+'<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">'
+'<embed src="./flash/article/indexPic.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#dfdfdf" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
+'</object>'
+'</p>'
+'</td>'
+'</tr>'
+'</table>';
var rusult='<table border="0" width="100%" cellspacing="0" cellpadding="0" height="235" align="center"><tr><td height="1"></td></tr><tr><td height="211"><p align="center"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'"><param name="allowScriptAccess" value="sameDomain"><param name="movie" value="./flash/article/indexPic.swf"><param name="quality" value="high"><param name="bgcolor" value="#dfdfdf"><param name="menu" value="false"><param name=wmode value="opaque"><param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'"><embed src="./flash/article/indexPic.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#dfdfdf" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></p></td></tr></table>';
//+'<img src="./image/article/index_r10_c2.jpg">';
return rusult;
}
function getProperty(property,objString) {
var objProperties=objString.split(",");
var result=null;
for(var i=0;i<objProperties.length;i++) {
var pros=objProperties[i];
//alert(pros);
if(pros.indexOf(property)>0) {
var iEnd=pros.indexOf("}");
if(iEnd<=0) {
iEnd=pros.length;
}
result=pros.substring(pros.indexOf(":")+2,iEnd-1);
break;
}
}
return result;
}
STRUTS
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.hcwy.struts.action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.hcwy.struts.User;
import com.hcwy.struts.form.ImageForm;
/**
* MyEclipse Struts
* Creation date: 04-12-2008
*
* XDoclet definition:
* @struts.action path="/image" name="imageForm" input="/form/image.jsp" scope="request" validate="true"
*/
public class ImageAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ImageForm imageForm = (ImageForm) form;
ArrayList list=new ArrayList();
for(int i=0;i<=10;i++){
User u=new User();
if(i<=9){
u.setName("0"+i);
u.setIndexPic("0"+i+".jpg");
}else{
u.setName(""+i);
u.setIndexPic(""+i+".jpg");
}
list.add(u);
}
request.setAttribute("list", list);
return mapping.findForward("index");
}
public static void main(String[] args) {
for(int i=0;i<=10;i++){
if(i<=9){
System.out.println("0"+i);
}else{
System.out.println(i);
}
}
}
}
VO
package com.hcwy.struts;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
import org.json.JSONObject;
public class User {
private String name;
private String indexPic;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIndexPic() {
return indexPic;
}
public void setIndexPic(String indexPic) {
this.indexPic = indexPic;
}
public String toString() {
// System.out.println("掉用了json的toString方法");
Map map = null;
try {
map = BeanUtils.describe(this);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
JSONObject json=new JSONObject(map);
return json.toString();
}
}