日期:2014-05-16  浏览次数:20389 次

js弹出层实现

一、----------------------得到数据的测试的action类

package com.cm12530.quannei.action;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.cm12530.quannei.base.action.BaseAction;
import com.cm12530.quannei.base.util.XmlCommon;
import com.cm12530.quannei.common.NewsCommon;
import com.cm12530.quannei.common.PictureCommon;
import com.cm12530.quannei.common.ReverseSort;
import com.cm12530.quannei.common.StarCommon;
import com.cm12530.quannei.common.VideoCommon;
import com.cm12530.quannei.domain.News;
import com.cm12530.quannei.domain.Picture;
import com.cm12530.quannei.domain.Star;
import com.cm12530.quannei.domain.Video;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

@SuppressWarnings("serial")
public class PluginAction extends BaseAction {
?private String urlPrefix;
?public String getUrlPrefix() {
??return urlPrefix;
?}

?public void setUrlPrefix(String urlPrefix) {
??this.urlPrefix = urlPrefix;
?}

?@SuppressWarnings("unchecked")
?public void getKeyWordList() {
??String content = this.getRequest().getParameter("con");
??content = XmlCommon.encode(content);
??List list = getStarKeywordList(content);

//??
//??List list = new ArrayList();
//??Star? star1 = new Star();
//??star1.setStarName("张学友");
//??Star? star2 = new Star();
//??star2.setStarName("赵薇");
//??Star? star3 = new Star();
//??star3.setStarName("许晴");
//??Star? star4 = new Star();
//??star4.setStarName("韩庚");
//??Star? star5 = new Star();
//??star5.setStarName("刘德华");
//??Star? star6 = new Star();
//??star6.setStarName("巩俐");
//??Star? star7 = new Star();
//??star7.setStarName("周杰伦");
//??list.add(star1);
//??list.add(star2);
//??list.add(star3);
//??list.add(star4);
//??list.add(star5);
//??list.add(star6);
//??list.add(star7);
??
?? if(list!=null){
??? Collections.sort(list,new ReverseSort()); //排序算法
??}

??JSONArray commentJson = JSONArray.fromObject(list);
??try {
???this.renderJson(this.getResponse(), commentJson, null);
??} catch (IOException e) {
???e.printStackTrace();
??}


?}

?@SuppressWarnings("unchecked")
?public void getKeyWordContent() {
??String keyword = this.getRequest().getParameter("k");
??keyword = XmlCommon.encode(keyword);
??String url = urlPrefix+"searchNews.action?keyword="+ keyword;
??//String url = "D:/imigoo_workspace_2/smallWindow/src/news.xml";
??Document doc = XmlCommon
????.getDocument(url);
??List newslist = null;
??Star star = null;
??if (doc != null) {
???newslist = getNewsList(doc.getRootElement()); // 得到资讯集合
???star = getStar(doc.getRootElement()); // 得到明星对象
??}

??List picList = getPictureList(keyword); // 得到图片集合
??List videoList = getVideoList(keyword); // 得到视频集合

??JSONArray jsonArr = new JSONArray();
??JSONObject obj1 = new JSONObject();
??obj1.put("newsList", newslist);

??JSONObject obj2 = new JSONObject();
??obj2.put("picList", picList);

??JSONObject obj3 = new JSONObject();
??obj3.put("videoList", videoList);

??JSONObject obj4 = new JSONObject();
??obj4.put("info", star);

??jsonArr.add(obj1);
??jsonArr.add(obj2);
??jsonArr.add(obj3);
??jsonArr.add(obj4);
??try {
???this.renderJson(this.getResponse(), jsonArr, null);
??} catch (IOException e) {
???e.printStackTrace();
??}
?}

?/************
? * 发送json封装返回数据
? *
? * @param response
? * @param jsonArray
? * @throws IOE