MyBlog--(6)文章详情页-articleinfo.jsp

articleinfo.jsp


开始~

<%@ page language="java" import="java.util.*,cn.edu.model.*,cn.edu.dao.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
head部分也和之前 以展示信息为主的jsp页面差不多
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'articleinfo.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link href="CSS/style.css" rel="stylesheet" type="text/css" />
</head>
body里面的第一句

之前是由doarticleinfo指过来的,里面存好了currentArticle

在这里从session中取出来就好

也把登录的用户取出来

<%
	// 取出当前文章
	Article article = (Article)session.getAttribute("currentArticle");
	// 取出当前登录的用户
	User u = (User)session.getAttribute("user");
%>


如果没有登录的用户,只显示一个,清音阁,,原作者的脑回路,,

有登录的用户就显示为realname的空间  后面依旧跟着一串,这里链接都没有写

        <%
        	if(u == null) {
        %>
        <td width="250" class="bigtitle">清音阁</td>
        <%} else {%>
        <td width="250" class="bigtitle"><%=u.getRealName() %>的空间</td>
        <%} %>
        <td width="30" align="center"><img src="images/house.gif" width="16" height="16" /></td>
        <td width="30" align="center"><a href="index.jsp">主页</a></td>
        <td width="30" align="center"><img src="images/ico_entry.gif" width="16" height="16" /></td>
        <td width="30" align="center"><a href="#">日志</a></td>
        <td width="30" align="center"><img src="images/ico_picture.gif" width="16" height="16" /></td>
        <td width="30" align="center"><a href="#">相册</a></td>
        <td width="30" align="center"><img src="images/ico_video.gif" width="16" height="16" /></td>
        <td width="30" align="center"><a href="#">视频</a></td>
        <td width="30" align="center"><img src="images/icon.gif" width="16" height="16" /></td>
        <td width="30" align="center"><a href="#">微博</a></td>
        <td width="30" align="center"><img src="images/ico_profile.gif" width="16" height="16" /></td>
        <td width="30" align="center"><a href="showinfo.jsp">资料</a></td>
        <td width="30" align="center"><img src="images/ico_share2.gif" width="16" height="16" /></td>
        <td width="30" align="center"><a href="#">分享</a></td>

接下来是博文内容~


精简了一下

"博文内容"的后面是一个文字链接  "[日志]+articleTitle"  指向articledetail1.jsp

用article对象取出发表时间、访问次数

下面p段落中展示内容

<td height="30" align="left" class="F12Strong">博文内容</td>
<a href="articledetail.jsp?aid=2" class="title">[日志]<%=article.getTitle() %></a>
发表时间<%=article.getPublishTime() %> 访问次数<%=article.getClicks() %>次
<p class="content"><%=article.getContent() %></p>

评论板块

声明一个CommentDAO对象,用它对评价进行操作

声明ArraryList变量,存储通过id查询到的评论

循环输出,通过评论找到评论的人


<!-- 评论板块 -->
          
          <tr>
            <td height="30" align="left" class="F12Strong">访客评论</td>
          </tr>
          
          <%
          	// 获取当前文章的所有评论信息
          	CommentDAO cdao = new CommentDAO();
          	ArrayList<Comment> clist = cdao.findByArticleId(article.getId());
          	for(int i = 0 ; i < clist.size(); i++) {
          		Comment comment = clist.get(i);
          		// 根据评论人的编号,查询评论人的信息
          		UserDAO adao = new UserDAO();
          		User cuser = adao.findById(comment.authorId);
          %>
          
          <tr>
            <td height="1" align="left" bgcolor="#dddddd">			</td>
          </tr>
          <tr>
            <td height="30" align="left" class="F12Gray"><b>[评论人]<%=cuser.getRealName() %></b></td>
          </tr>
          <tr>
            <td height="30" align="left"><%=comment.content %></td>
          </tr>
          <tr>
            <td height="30" align="right" class="F12Gray"><%=comment.commmentTime %></td>
          </tr>
          <%} %>

如果u为空,说明没有登录

提示登录

如果已经登录

有一个textarea来输入评论内容 commentcontent

下面发布按钮是一张图片

<%
         	if(u==null){
         %>
                <tr>
                  <td  height="50" align="center" valign="middle"><label>尊敬的用户,请<a href="login.jsp" class="L12Gray">登陆</a>后发表评论 ,或者<a href="register.jsp" class="L12Gray">注册新用户</a>进行登录</label></td>
                </tr>
          <%} else { %>      
          <tr>
            <td height="30" align="left" class="F12Strong">发表评论</td>
          </tr>
          <tr>
            <td height="30" align="left"><form id="form2" name="form2" method="post" action="docomment.jsp">
              <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="30" align="right">评论:</td>
                  <td><label>
                    <textarea name="commentcontent" rows="5" class="inputTextW480"></textarea>
                  </label></td>
                </tr>
                <tr>
                  <td height="30" align="right"> </td>
                  <td><label>
                    <input type="image" name="imageField2" src="images/publish.jpg" />
                  </label></td>
                </tr>               
              </table>
                        </form>
            </td>
          </tr>
          <%} %>

评论提交到docomment.jsp

后面部分和其他页面相同,没登陆显示登录框,已登录显示个人资料


docomment.jsp


<%@ page language="java" import="java.util.*,cn.edu.luas.model.*,cn.edu.luas.dao.*" pageEncoding="UTF-8"%>
<!-- 处理添加评论的页面 -->
<%
	// 1. 设置编码格式
	request.setCharacterEncoding("UTF-8");
	// 2. 获取评论内容
	String content = request.getParameter("commentcontent");
	
	// 3. 取出当前文章
	Article article = (Article)session.getAttribute("currentArticle");
	int articleId = article.getId();
	
	// 4. 取出当前用户
	User user = (User)session.getAttribute("user");
	int authorId = user.getId();
	
	// 5. 创建一个评论对象
	Comment comment = new Comment(); 
	comment.authorId = authorId;	// 设置评论发表人的属性值
	comment.articleId = articleId;	// 设置评论的文章编号的属性之
	comment.content = content;		// 设置评论内容的属性值
	
	// 6. 把评论插入到数据库
	CommentDAO dao = new CommentDAO();
	dao.addComment(comment);
	
	// 7. 返回文章详细信息页面
	response.sendRedirect("articleinfo.jsp");
	
%>







































  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值