67,513
社区成员
发帖
与我相关
我的任务
分享
function addComment() {
//以下是获取fckeditor的值
var fck=FCKeditorAPI.GetInstance("u_comment_a.commentContent").GetXHTML(true);
var userId=document.getElementById("userId").value;
var articleId=document.getElementById("articleId").value;
//fck=encodeURI(encodeURI(fck));//转码
alert("用户Id:"+userId);
alert("文章Id:"+articleId);
alert("评论内容:"+fck);
var xhr=new createXmlHttpRequest();//第一步,获取XHR对象
xhr.onreadystatechange=function (){//第二部,写监听函数
if (xhr.readyState == 4) {//条件判定
if (xhr.status == 200||xhr.status == 304) {
alert("评论成功!");
location.reload() ;
}
}
}
xhr.open("post","UserComment!addUsercommentarticle",true);//链接请求
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")//设置一下请求头
xhr.send("u_comment_a.commentContent="+fck+"&users.userId="+userId+"&article.articleId="+articleId);//发送
//return false;
}
/**
* 添加一条评论的方法
* @return
*/
public void addUsercommentarticle() {
System.out.println(article.getArticleId()+"--------------------articleId--------------------");
System.out.println(users.getUserId()+"--------------------userId--------------------");
//解码
try {
u_comment_a.setCommentContent(java.net.URLDecoder.decode(u_comment_a.getCommentContent(), "UTF-8"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
System.out.println(u_comment_a.getCommentContent()+"--------------------u_comment_a------------------------");
try {
users = UserManagerBean.getUserById(users.getUserId());
article = ArticleManagerBean.getArticleById(article.getArticleId());
//每当评论一次就添加一次被评论的次数
article.setCommentCount(article.getCommentCount()+1);
//提交更新
ArticleManagerBean.updateArticle(article);
//再获取一次
// article = ArticleManagerBean.getArticleById(article.getArticleId());
System.out.println(article.getCommentCount()+"====================================");//打印评论次数看看
//设置评论所属文章及评论者
u_comment_a.setArticle(article);
u_comment_a.setUsers(users);
} catch (Exception e) {
e.printStackTrace();
}
UserCommentArticleManagerBean.addU_A(u_comment_a);
//return "commentSuccess";
}
98--------------------articleId--------------------
9--------------------userId--------------------
<p>--------------------u_comment_a------------------------