先是jquery代码:
$("input[name='btn_up']").click(function(){
var val = $(this).attr("data_id");
$.ajax({
type: "POST",
url: '<s:url action="count"></s:url>',
data: "tag=up&id="+val,
success: function(msg){
alert("success : "+msg);
$("#count_up_"+val).html(msg);
}
});
});
$("input[name='btn_down']").click(function(){
var val = $(this).attr("data_id");
$.ajax({
type: "POST",
url: '<s:url action="count"></s:url>',
data: "tag=down&id="+val,
success: function(msg){
$("#count_down_"+val).html(msg);
}
});
});
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
页面代码:
<input type="button" value="顶" name="btn_up" data_id="${id}" />
<span id="count_up_${id}">${praiseCount}</span>
<input type="button" value="踩" name="btn_down" data_id="${id}" />
<span id="count_down_${id}">${flameCount}</span>
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
CountAction代码:
public class CountAction extends DrivenBase {
public static final String CHECK_SUCCESS="checksuccess";
///
@Override
protected String check(){
// 返回结果
return SUCCESS;
}
public String execute(){
/*if(target == null)
return ERROR;*/
// 接收参数
// System.out.println("======params.getMessageId====="+
// ((SiteMessageWordParams)params).getMid());
/*SiteMessage message =
messageBiz.load(((SiteMessageWordParams)params).getMid());*/
target = targetBiz.load(params.getId());
System.out.println(" target = "+target);
if (target == null) {
return ERROR;
}
if (tag!=null&& tag.trim().equalsIgnoreCase("up")) {
target.setPraiseCount(target.getPraiseCount() == null?
1:target.getPraiseCount()+1);
}else{
target.setFlameCount(target.getFlameCount() == null ? 1: target.getFlameCount()+1);
}
// target.setCallName(params.getCallName());
//target.setMessage(params.getMessage());
//
// target.setConents(params.getConents());
// http://localhost:8080/wyb/site/message/reply/list?wordId=1
// 执行处理
targetBiz.update(target);
//希望添加成功之后跳转到这个页面,而不是返回drivebase里面的连接
/*"http://localhost:8080/wyb/site/message/reply/list?wordId="
+ServletActionContext.getRequest().getParameter("mid");*/
System.out.println(" ==== update == success ");
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.print(tag!=null&& tag.trim().equalsIgnoreCase("up")
? target.getPraiseCount():target.getFlameCount());
} catch (IOException e) {
e.printStackTrace();
}finally{
if (out!=null) {
out.close();
}
}
return null;
}
///
@Override
public StringRender getPageTitle(){
return super.getPageTitle().add(SiteMessageWord.CLASS_TEXT + "添加");
}
private String tag;
希望有人提交更好的顶和踩方法
/**
* @param tag the tag to set
*/
public void setTag(String tag) {
this.tag = tag;
}
}