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

struts2 jquery json 实现ajax技术 返回list
jsp页面:
      
  <input type="hidden" id="currentPage2" value="1">
 <br/><br/><div></div>
										<DIV id=in_send>
		<div align="left" style="padding-left:40px; font-weight:blod; margin-top:10px;" >发表评论:</div>
			<table width="720" border="0" cellspacing="5" cellpadding="0"><tr>
			<td align="left">姓 名:</td>
			<td  align="left"><input type="text" name="picCriticismName" id="picCriticismName" style="width:220px"  maxlength="49" tabindex=1>
			<div id="nmerror" style="float:left;" >*姓名最长为50字节</div></td></tr>
			<tr><td  align="left" valign="top" class="f14" id="reTitle">内 容:</td>
			<td  align="left" ><textarea name="picCriticismContent" id="picCriticismContent" style="width:520px;height:155px"  tabindex=4></textarea>
			</td></tr>
			<tr id="3_err" style="display:none"><td>&nbsp;</td><td><div class="error" id="3_err_con"></div></td></tr>
			<tr><td valign="top">&nbsp;</td>
			<td valign="top" align="left" >
			<input  type="button" onclick="good()" value="发表评论"  >
			</td>
			</tr></table>

										
										
										</DIV>
									</DIV>

xml配置文件:
  <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
    <!-- 
               作者:ljz
              时间:2010/09/15           
    -->
<struts>

  <package name="piccriticism"  extends ="json-default">
  <action name="addPicCriticism" class="PicCriticismBean" method="addPicCriticism">   
	
<result  name="success" type="json">
<param name="includeProperties">
	list5\[\d+\]\.criticismContent,list5\[\d+\]\.criticismName,list5\[\d+\]\.criticismIp,list5\[\d+\]\.criticismTime,list5\[\d+\]\.totalPage,list5\[\d+\]\.currentPage
</param>
</result>   
</action>
</package>
</struts>



package cn.ljzblog.ljz.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import test.SuperPicCriticims;
import cn.ljzblog.ljz.common.CalculatePage;
import cn.ljzblog.ljz.common.Page;
import cn.ljzblog.ljz.model.PicCriticism;
import cn.ljzblog.ljz.model.PicCriticismTemp;
import cn.ljzblog.ljz.service.PicCriticismServices;
import cn.ljzblog.ljz.util.ActionContextUtil;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;



/**
 * 相片评论
 * @author ljz
 * @time 2010/10/03
 */
public class PicCriticismAction extends ActionSupport implements ModelDriven<PicCriticismTemp>{
	 private PicCriticismTemp pt = new PicCriticismTemp();
	 private SuperPicCriticims sc = new SuperPicCriticims();
	 private ActionContextUtil acu = new ActionContextUtil();
	 private PicCriticism pc = new PicCriticism();
	 private String pictureDetail;
	 private String picCriticismName;
	  private String currentPage2 = "1";
	   private Page page = new Page();
	   private String firstOrLast = new String();//判断是否是首页或者是尾页
		private CalculatePage cal = new CalculatePage();
		private PicCriticismServices picCriticismServices;
		private int currentPage  = 1;
		private List<PicCriticismTemp> list5 ;
		private String picCriticismId;
   public String addPicCriticism(){
	   System.out.println("进入评论先相片action");
	   System.out.println(this.getFirstOrLast());
	   System.out.println(pt.getPicName()+"相片名称");
	   page.setPageSize(5);
	   //String sql = "select t.pic_criticism_content,t.piccriticismip,t.piccriticismtime,t.piccriticismname from t_pic_criticism t inner join t_picture pic on t.picture_id