67,512
社区成员
发帖
与我相关
我的任务
分享
<div id="myview" style="width: 930px;">
<table class="table table-bordered">
<tbody>
<tr class="active">
<th><strong>发表你的影评(请先登录后发表)</strong></th>
</tr>
<tr class="warning">
<th><input class="form-control" id="title" name="myreview"
placeholder=" 请输入" type="text"
style="width: 500px;height: 100px;" > <span
id="titleCount"
style="color:#9B9B9B;text-decoration: none;font-size:12px;">还可以输入200个字</span>
<input id="addreview" name="addreview" type="submit"
style="width: 50px;height: 40px;" value="提交">
</th>
</tr>
</tbody>
</table>
</div>
$("#addreview").click(function() {
$.ajax({
type : "POST",
url : "${pageContext.request.contextPath}/user",
data : {"method" : "isLogined",
},
dataType : "json",
success : function(data){
var title= $("#title").val();
//解析响应数据
var html="<div style='background-color:rgba(255,228,225,0.5) ;border: 1px dotted #dddddd; width: 930px; padding: 10px 10px; margin: 10px 0 10px 0;'><strong>${USER.username}的影评"+"</strong></br> <p>"+title+"</p></div>";
//循环结束后,添加到div中
$("#myview").before(html);
},
error: function(){
alert("请先登录后发表");
}
});
});
if(method.equals("isLogined")){
//判断是否登录
isLogined(req,resp);
}
//实现是否已经登录
private void isLogined(HttpServletRequest req, HttpServletResponse resp) throws Exception{
String myreview = req.getParameter("myreview");////这里获取出来是null的
System.out.println(myreview);
HttpSession session=req.getSession();
User user=(User) session.getAttribute("USER");
System.out.println(user.username);
if(user.username==null){
//用户未登录
resp.getWriter().write("flase");
}else{
//已经登录
//把用户的影评放进数据库
user.setMyreview(myreview);(myreview为null,以至于这步错了)
userService.addReview(user);(myreview为null,以至于这步错了)
resp.getWriter().write("true");
}
}