九色porny自拍视频在线观看,免费播放片a高清在线观看,凹凸av导航大全精品http://www.aygfsteel.com/chucky/category/41895.htmlzh-cnFri, 09 Oct 2009 16:05:54 GMTFri, 09 Oct 2009 16:05:54 GMT60Blog系統開發 16。 收工http://www.aygfsteel.com/chucky/articles/297458.htmlChuckyChuckyThu, 08 Oct 2009 09:04:00 GMThttp://www.aygfsteel.com/chucky/articles/297458.htmlhttp://www.aygfsteel.com/chucky/comments/297458.htmlhttp://www.aygfsteel.com/chucky/articles/297458.html#Feedback0http://www.aygfsteel.com/chucky/comments/commentRss/297458.htmlhttp://www.aygfsteel.com/chucky/services/trackbacks/297458.html 這方面沒有什么感覺,總之把跟這個項目相關的東西放在一起(src和web相關的東西);有興趣可以下來看看。
blog_servlet

Ok 跟blog_servlet相關的東西到這里結束了,下周開始做blog Struts相關的項目。



Chucky 2009-10-08 17:04 發表評論
]]>
Blog系統開發 15. 小細節 (3) 分頁問題 PageTag類http://www.aygfsteel.com/chucky/articles/297375.htmlChuckyChuckyWed, 07 Oct 2009 08:58:00 GMThttp://www.aygfsteel.com/chucky/articles/297375.htmlhttp://www.aygfsteel.com/chucky/comments/297375.htmlhttp://www.aygfsteel.com/chucky/articles/297375.html#Feedback0http://www.aygfsteel.com/chucky/comments/commentRss/297375.htmlhttp://www.aygfsteel.com/chucky/services/trackbacks/297375.html&n...  閱讀全文

Chucky 2009-10-07 16:58 發表評論
]]>
Blog系統開發 14. 小細節 (2) 分頁問題displaytag Part(2)http://www.aygfsteel.com/chucky/articles/297355.htmlChuckyChuckyWed, 07 Oct 2009 06:37:00 GMThttp://www.aygfsteel.com/chucky/articles/297355.htmlhttp://www.aygfsteel.com/chucky/comments/297355.htmlhttp://www.aygfsteel.com/chucky/articles/297355.html#Feedback0http://www.aygfsteel.com/chucky/comments/commentRss/297355.htmlhttp://www.aygfsteel.com/chucky/services/trackbacks/297355.html 集中在管理頁面里,譬如對博文的管理或者是針對comments的管理;相對而言category似乎并不需要使用分頁;
很少會有人開幾十個不同的分類吧 XD。

好吧,我們來比較一下,displaytag和原來的代碼有什么不同。

這是原先的頁面 網頁的code:
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"%>
 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 3     "http://www.w3.org/TR/html4/loose.dtd">
 4 <%@page import="java.util.List" %>
 5 <%@page import="java.text.SimpleDateFormat" %>
 6 <%@page import="com.blog.Blog" %>
 7 <%@page import="com.blog.Category" %>
 8 <%@page import="com.blog.Comment" %>
 9 <script type="text/javascript" language="JAVASCRIPT">
10     function del(){
11         var msg = "您真的確定要刪除嗎?\n\n請確認!";
12         if (confirm(msg)){
13             return true;
14         }else{
15             return false;
16         }
17     }
18 </script>
19 <div id="mainContent">
20     <% Category category = (Category) request.getAttribute("category");
21         if (category!=null){
22             out.print("<h3><a href='"+request.getContextPath()+"'>JAVA試驗田</a>»"+category.getName()+"</h3>");
23         }
24     %>
25     <table>
26         <tr>
27             <th>主題</th>
28             <th></th>
29             <th></th>
30         </tr>
31 
32     <% List blogs = (List) request.getAttribute("blogs");
33        if (blogs != null){
34            SimpleDateFormat fDate = new SimpleDateFormat("yyyy-MM-dd");
35            SimpleDateFormat fTime = new SimpleDateFormat("HH:mm");
36            for (int i=0;i<blogs.size();i++){
37                Blog blog = (Blog)blogs.get(i);%>
38                <tr>
39                    <td><href="<%=request.getContextPath()%>/BlogServlet?method=get&bid=<%=blog.getId()%>"><%=blog.getTitle()%></a> (<%=fDate.format(blog.getDate())%> <%=fTime.format(blog.getDate())%>)</td>
40                     <td> <href="<%=request.getContextPath()%>/BlogServlet?method=edit&bid=<%=blog.getId()%>"><img src="<%=request.getContextPath()%>/admin/img/edit.gif" border=0 alt="編輯"/></a></td>
41                    <td>  <href="<%=request.getContextPath()%>/BlogServlet?method=delete&bid=<%=blog.getId()%>" onclick="javascript:return del()"><img src="<%=request.getContextPath()%>/admin/img/delete.gif" border=0 alt="刪除"/></a></td>
42 
43                </tr>
44                
45     <%       }
46        }
47     %>
48     </table>
49     <!-- end #mainContent --></div>
50 <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
51 

對比一下使用displayTag的頁面顯示

再看一下新的網頁的寫法:
 1 <%@taglib uri="http://displaytag.sf.net" prefix="display" %>
 2 <%@page import="java.util.List" %>
 3 <%@page import="java.text.SimpleDateFormat" %>
 4 <%@page import="com.blog.Blog" %>
 5 <%@page import="com.blog.Category" %>
 6 <%@page import="com.blog.Comment" %>
 7 <script type="text/javascript" language="JAVASCRIPT">
 8     function del(){
 9         var msg = "您真的確定要刪除嗎?\n\n請確認!";
10         if (confirm(msg)){
11             return true;
12         }else{
13             return false;
14         }
15     }
16 </script>
17 <div id="mainContent">
18     <% Category category = (Category) request.getAttribute("category");
19             if (category != null) {
20                 out.print("<h3><a href='" + request.getContextPath() + "'>JAVA試驗田</a>»" + category.getName() + "</h3>");
21             }
22     %>
23     <display:table name="blogs" id="blog" pagesize="10" requestURI="/Blog/BlogServlet">
24         <display:column property="title" title="主題"/>
25         <display:column property="date" format="{0,date,yyyy-MM-dd  HH:mm}" title="日期"/>
26         <display:column title="操作">
27             <href="<%=request.getContextPath()%>/BlogServlet?method=edit&bid=${blog.id}"><img src="<%=request.getContextPath()%>/admin/img/edit.gif" border=0 alt="編輯" /></a>
28             <href="<%=request.getContextPath()%>/BlogServlet?method=delete&bid=${blog.id}" onclick="javascript:return del()"><img src="<%=request.getContextPath()%>/admin/img/delete.gif" border=0 alt="刪除"/></a>
29             </display:column>
30         </display:table>
31         <!-- end #mainContent --></div>
32 <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
33 
34 
23行指定了displayTag顯示每頁10條數據。



Chucky 2009-10-07 14:37 發表評論
]]>
Blog系統開發 13. 小細節 (2) 分頁問題displaytag Part(1)http://www.aygfsteel.com/chucky/articles/297256.htmlChuckyChuckyMon, 05 Oct 2009 07:07:00 GMThttp://www.aygfsteel.com/chucky/articles/297256.htmlhttp://www.aygfsteel.com/chucky/comments/297256.htmlhttp://www.aygfsteel.com/chucky/articles/297256.html#Feedback0http://www.aygfsteel.com/chucky/comments/commentRss/297256.htmlhttp://www.aygfsteel.com/chucky/services/trackbacks/297256.html 在這個項目里,對于分頁問題,我采取2種處理的方法。對于管理頁面表格型的記錄采用displayTag組件;
而對于那些博文或者評論采用自己寫的PageTags類來管理。

1. displayTag組件

上面的圖片可以看出:事實上這個display tag庫就是用來顯示表格的;給它一個對象的list,它將搞定類似顯示列,排序,分頁等等事務,并以表格的形式顯示出來。

a. 安裝:
   將displaytag-version.jar 文件與以下5個文件一起放置在應用的WEB-INF/lib目錄里
  • commons-logging
  • commons-lang
  • commons-collections
  • commons-beanutils
  • log4j
   在使用的時候,在jps頁面中,
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>

b. 使用:
   這里使用blog列表做例子
 <% List blogs = (List) request.getAttribute("blogs");%>
    
<h2>文章管理</h2>
<display:table name="blogs" htmlId="tab" pagesize="10" />
每頁顯示10條記錄

對于每條記錄我們可能有顯示要求
<display:table name="blogs" id=" blog" htmlId="tab" pagesize="10" >
    
<display:column property="id" title="編號"/>
    
<display:column property="title" title="主題"/>
    
<display:column property="category" title="類別"/>
    
<display:column property="date" format="{0,date,yyyy-MM-dd  HH:mm:ss}" title="日期",sortable="true"/>
    
<display:column title="操作">
        
<href="/Blogs/BlogServlet?method=edit&id=${blog.id}"><img src="/Blogs/admin/img/edit.gif" border=0 /></a>
                
<href="/Blogs/BlogServlet?method=delete&id=${blog.id}" onclick="javascript:return del()"><img src="/Blogs/admin/img/delete.gif" border=0 /></a>|
                
<href="/Blogs/CommentServlet?method=list&bid=${blog.id}">管理評論</td> 
    
</display:column>
    
</display:table>
比如id字段顯示為 標號;title主題;category類別;日期么安裝年-月-日 小時:分鐘:秒的格式顯示;并且可以手動選擇排序。
是不是很簡單。

c.其他問題:
  配置文件displaytag.properties,需要放置在src目錄的根部,主要顯示一些文字之類的設置,支持localization,但是要注意的是,文件必須轉換成unicode才可以正常顯著。
以下是displaytag_Zh_CN.properties的示例:
 1 #sort.behavior=list
 2 #sort.amount=list
 3 #basic.empty.showtable=true
 4 #basic.msg.empty_list=No results matched your criteria.
 5 #paging.banner.placement=top
 6 #paging.banner.onepage=<span class="pagelinks"></span>
 7 export.types=csv excel xml pdf rtf
 8 export.excel=true
 9 export.csv=true
10 export.xml=true
11 export.pdf=true
12 export.rtf=true
13 export.excel.class=org.displaytag.export.excel.DefaultHssfExportView
14 export.pdf.class=org.displaytag.export.DefaultPdfExportView
15 export.rtf.class=org.displaytag.export.DefaultRtfExportView
16 # if set, file is downloaded instead of opened in the browser window
17 #export.[mymedia].filename=
18 paging.banner.placement=bottom
19 # messages
20 
21 basic.msg.empty_list=\u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u8BB0\u5F55
22 basic.msg.empty_list_row=<tr class="empty"><td colspan="{0}">\u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u8BB0\u5F55</td></tr>
23 error.msg.invalid_page=\u65E0\u6548\u9875\u9762
24 
25 export.banner=<div class="exportlinks">Export options: {0}</div>
26 export.banner.sepchar= |
27 
28 paging.banner.item_name=
29 paging.banner.items_name=
30 
31 paging.banner.no_items_found=
32 paging.banner.one_item_found=
33 paging.banner.all_items_found=
34 paging.banner.some_items_found=
35 
36 paging.banner.full=<span class="pagelinks"><font align>[<a href="{1}">|<</a>/<a href="{2}"><</a>] {0[<a href="{3}">></a>/<a href="{4}">>|</a>]</span>
37 paging.banner.first=<span class="pagelinks">[\u9996\u9875/\u4E0A\u4E00\u9875] {0[<a href="{3}">\u4E0B\u4E00\u9875</a>/<a href="{4}">\u5C3E\u9875</a>]</span>
38 paging.banner.last=<span class="pagelinks">[<a href="{1}">\u9996\u9875</a>/<a href="{2}">\u4E0A\u4E00\u9875</a>] {0[\u4E0B\u4E00\u9875/\u5C3E\u9875]</span>
39 paging.banner.onepage=<span class="pagelinks">{0}</span>
40 
41 paging.banner.page.selected=<strong>{0}</strong>
42 paging.banner.page.link=<a href="{1}" title="{0}">{0}</a>
43 paging.banner.page.separator=, \
38行paging.banner.placement=bottom 指定分頁欄出現在表格的下面,當然還有top/both兩個選擇。
  
 



Chucky 2009-10-05 15:07 發表評論
]]>
Blog系統開發 12. 小細節 (1)http://www.aygfsteel.com/chucky/articles/297255.htmlChuckyChuckyMon, 05 Oct 2009 06:26:00 GMThttp://www.aygfsteel.com/chucky/articles/297255.htmlhttp://www.aygfsteel.com/chucky/comments/297255.htmlhttp://www.aygfsteel.com/chucky/articles/297255.html#Feedback0http://www.aygfsteel.com/chucky/comments/commentRss/297255.htmlhttp://www.aygfsteel.com/chucky/services/trackbacks/297255.html 在項目設計的時候,普通用戶可以看博客,發表評論;為了避免不必要的麻煩,將普通用戶的操作特別的寫一個servlet,這樣也比較容易控制。
HomeServlet主要就是負責這個任務。
在HomeServlet里面主要就是兩個方法,為了配合以后的頁面設計,相對之前的BlogServlet等等,相對復雜一點(其實還好)。

讓我們來看看這個Sql語句的作用
sql= select b.id as id,b.title as title,b.content as content,b.date as date,c.name as category,categoryId,comments from
(
select blog.id as id ,blog.title as title,blog.category_id as categoryId,count(comment.blog_id) as comments,blog.content as content,blog.date as date from blog
left
 join comment on blog.id = comment.blog_id group by blog.id) as b, category c
where categoryId = c.id
order by date desc;
首先
select blog.id as id ,blog.title as title,blog.category_id as categoryId,count(comment.blog_id) as comments,blog.content as content,blog.date as date from blog
left join comment on blog.id = comment.blog_id group by blog.id
comment表中對blog_id一致的記錄做統計,與blog表左連接;
然后再blog新表與category根據categoryId做連接。

然后修改一下Blog類,添加一個comments屬性(記錄此blog對象所包含的評論數目)。

2.對blog.content做下處理,在顯示所有博文的時候,對blog.content的內容做一個簡報。
很簡單的一個getBriefContent()方法:
public String getBriefContent() {
        StringBuffer briefContent 
= new StringBuffer(content);
        
int length = 200;
        
if (briefContent.length() < length) {
            length 
= briefContent.length();
        }
        briefContent 
= briefContent.delete(length, briefContent.length());

        
//filter html mark;
        briefContent.append(" ..");
        
return briefContent.toString();
    }
限定200字符長度,如果博文內容多于200字符,那么取前200字符;否則直接貼上博文內容。

3.對blog.content另一個修改。因為寫博文的時候,可能所選用的字體啊什么每次都不同,以至于在瀏覽所有博文的時候會很亂;
所以以下doFilter(StringBuffer sb)方法,主要對文字進行過濾,將充滿HTML MARK的文章過濾一下。
private StringBuffer doFilter(StringBuffer source) {
        StringBuffer header 
= new StringBuffer(source);
        
while((header.indexOf("<")!=-1)&&(header.indexOf(">")!=-1)){
           
int startPos = header.indexOf("<");
           
int endPos = header.indexOf(">");
            header 
= header.delete(startPos, endPos+1);
        }
        
return header;
    }
因此getBriefContent()方法也要插上一句(Line 3):
 1 public String getBriefContent() {
 2         StringBuffer briefContent = new StringBuffer(content);
 3         briefContent = doFilter(briefContent);
 4         int length = 200;
 5         if (briefContent.length() < length) {
 6             length = briefContent.length();
 7         }
 8         briefContent = briefContent.delete(length, briefContent.length());
 9 
10         //filter html mark;
11         briefContent.append(" ..");
12         return briefContent.toString();
13     }





Chucky 2009-10-05 14:26 發表評論
]]>
Blog系統開發 11. 用戶驗證的問題http://www.aygfsteel.com/chucky/articles/297017.htmlChuckyChuckyWed, 30 Sep 2009 06:47:00 GMThttp://www.aygfsteel.com/chucky/articles/297017.htmlhttp://www.aygfsteel.com/chucky/comments/297017.htmlhttp://www.aygfsteel.com/chucky/articles/297017.html#Feedback0http://www.aygfsteel.com/chucky/comments/commentRss/297017.htmlhttp://www.aygfsteel.com/chucky/services/trackbacks/297017.html 上一節,在處理完login事務以后,我們可以訪問某個頁面對自己的博文或者博文分類等等進行操作。
但是由于網頁的關系,如果沒有對每頁進行用戶認證,而我們知道準確的地址的話,我們可以直接訪問地址來對數據進行操作。
比如:
http://localhost:8080/Blog/BlogServlet?method=list
可以查看所有的博文;而
http://localhost:8080/Blog/BlogServlet?method=delete&cid=1
這個地址可以對編號為1的博文進行刪除操作。
所以我們必須對每一頁或者沒一次操作進行用戶認證。因為user對象是放置在session中的,所有我們可以每次通過檢測session內容來達到驗證的效果。

在這里,我寫了一個輔助類UserValidator,來簡化操作。
package com.blog.utils;

import com.blog.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *
 * 
@author Chucky
 
*/
public class UserValidator {
    
public static boolean isValid(HttpServletRequest request){
        HttpSession session 
= request.getSession();
        User user 
= (User) session.getAttribute("user");
        
return user!=null?true:false;
    }
}
一般Servlet的里面,可以直接把UserValidator的檢驗直接放置在processRequest方法里,如果檢驗失敗的話,轉到用戶登錄界面
 1 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
 2             throws ServletException, IOException {
 3         response.setContentType("text/html;charset=UTF-8");
 4         request.setCharacterEncoding("UTF-8");
 5 
 6         String method = request.getParameter("method");
 7 
 8         if (!UserValidator.isValid(request)) {
 9             response.sendRedirect(request.getContextPath()+"/admin/");
10         } else {
11             if (method.equals("add")) {
12                 add(request, response);
13             } else if (method.equals("delete")) {
14                 delete(request, response);
15             } else if (method.equals("edit")) {
16                 preEdit(request, response);
17             } else if (method.equals("update")) {
18                 update(request, response);
19             } else if (method.equals("list")) {
20                 list(request, response);
21             } else if (method.equals("get")) {
22                 get(request, response);
23             } else if (method.equals("preAdd")) {
24                 preAdd(request, response);
25             }
26         }
27     }
而一些直接讀取的jsp頁面,也可以把驗證直接寫在頁面里。
<% User user = (User)session.getAttribute("user");
   if (user == null){
   
response.sendRedirect(request.getContextPath()+"/admin/");
   }
%>




Chucky 2009-09-30 14:47 發表評論
]]>
Blog系統開發 10. UserServlethttp://www.aygfsteel.com/chucky/articles/296997.htmlChuckyChuckyWed, 30 Sep 2009 04:22:00 GMThttp://www.aygfsteel.com/chucky/articles/296997.htmlhttp://www.aygfsteel.com/chucky/comments/296997.htmlhttp://www.aygfsteel.com/chucky/articles/296997.html#Feedback0http://www.aygfsteel.com/chucky/comments/commentRss/296997.htmlhttp://www.aygfsteel.com/chucky/services/trackbacks/296997.html 所以user將被寫在session里面,用以在某些管理頁面達到認證作用。
 1 private void login(HttpServletRequest request, HttpServletResponse response)
 2             throws ServletException, IOException {
 3         String userName = request.getParameter("username");
 4         String password = request.getParameter("password");
 5         String sql = "select id,username,password from users where username = ? and password = ?";
 6         String params[] = {userName, password};
 7         List users = null;
 8 
 9         QueryRunner qr = DbHelper.getQueryRunner();
10         try {
11             users = (List) qr.query(sql, new BeanListHandler(User.class), params);
12         } catch (SQLException ex) {
13             Logger.getLogger(UserServlet.class.getName()).log(Level.SEVERE, null, ex);
14         }
15         if (users.size()!=0) {
16             User user = (User) users.get(0);
17             HttpSession session = request.getSession();
18             session.setAttribute("user", user);
19             response.sendRedirect(request.getContextPath()+"/BlogServlet?method=list");
20         } else {
21             request.setAttribute("message""錯誤的用戶名或密碼");
22             request.getRequestDispatcher("/admin/login.jsp").forward(request, response);
23         }
24     }

logout相對很簡單,使session失效即可
1 private void logout(HttpServletRequest request, HttpServletResponse response)
2             throws ServletException, IOException {
3         HttpSession session = request.getSession();
4         session.invalidate();
5         response.sendRedirect(request.getContextPath());
6     }

modifyPassword
 1  private void modify(HttpServletRequest request, HttpServletResponse response)
 2             throws ServletException, IOException {
 3         String oldPassword = request.getParameter("oldPassword");
 4         String newPassword = request.getParameter("newPassword");
 5         String confirmPassword = request.getParameter("confirmPassword");
 6 
 7         HttpSession session = request.getSession();
 8         User user = (User) session.getAttribute("user");
 9         if (!user.getPassword().equals(oldPassword)) {
10             request.setAttribute("message""與原密碼不匹配");
11         } else {
12             if (!newPassword.equals(confirmPassword)) {
13                 request.setAttribute("message""新密碼與確認密碼不匹配");
14             } else {
15                 String sql = "update users set password =? where id = "+ user.getId();
16                 QueryRunner qr = DbHelper.getQueryRunner();
17                 try {
18                     qr.update(sql, newPassword);
19                 } catch (SQLException ex) {
20                     Logger.getLogger(UserServlet.class.getName()).log(Level.SEVERE, null, ex);
21                 }
22                  request.setAttribute("message""密碼修改成功");
23             }
24         }
25         request.getRequestDispatcher("/admin/modifyPassword.jsp").forward(request, response);
26     }




Chucky 2009-09-30 12:22 發表評論
]]>
主站蜘蛛池模板: 恭城| 庆阳市| 浠水县| 车致| 山东| 广南县| 年辖:市辖区| 灌云县| 德江县| 富川| 阜新| 金秀| 大冶市| 安陆市| 襄城县| 北流市| 翁源县| 新建县| 龙川县| 花垣县| 虞城县| 瑞金市| 元氏县| 芷江| 东安县| 长宁区| 青海省| 锦屏县| 盱眙县| 合水县| 汤原县| 沙田区| 宝丰县| 玉门市| 北辰区| 济源市| 西林县| 彝良县| 中方县| 三台县| 渭源县|