实际上,我想构建一个 JSP 来显示来自数据库的帖子,并自动为每个帖子提供一个写入文本的位置,当用户在评论框中输入文本时,该文本应该保存在数据库中并立即出现文本并再次出现新文本位置(评论框) 应出现用于输入文本。就像 Facebook 一样,我从互联网上搜索分配,但没有找到任何机构可以帮助我的任何解决方案,在这种情况下将不胜感激。
问问题
1293 次
2 回答
0
http://www.includehelp.com/java/comment-box-design-in-bootstrap-using-ajax-mysql-and-jsp.aspx
按照这个,你可以实现相同的
于 2017-03-09T05:21:08.827 回答
0
从头开始实施就像重新发明轮子。最好的办法是使用 jQuery 库,例如jQuery 注释文档 ,它将为您提供整个结构。您需要为 ajax 调用 servlet 提供实现以获取和发布评论。模板将在那里,唯一的事情是您需要为功能提供实现。让我知道任何需要的输入或使用它的挑战。
从给定的库文档中:
1)将以下内容添加到您的 HTML 文件中
<link rel="stylesheet" type="text/css" href="css/jquery-comments.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-comments.js"></script>
2) 初始化库
$('#comments-container').comments({
profilePictureURL: 'https://app.viima.com/static/media/user_profiles/user-icon.png',
getComments: function(success, error) {
var commentsArray = [{
id: 1,
created: '2015-10-01',
content: 'Lorem ipsum dolort sit amet',
fullname: 'Simon Powell',
upvote_count: 2,
user_has_upvoted: false
}];
success(commentsArray);
}
});
和需要定制getComments
。postComments
因此,对于发表评论,需要使用以下函数,映射到您的 servlet 映射,发表评论,进行 ajax 调用:
$('#comments-container').comments({
postComment: function(commentJSON, success, error) {
$.ajax({
type: 'post',
url: '/api/comments/',
data: commentJSON,
success: function(comment) {
success(comment)
},
error: error
});
}
});
于 2017-02-17T06:59:12.120 回答