两亩三分地

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  17 随笔 :: 20 文章 :: 2 评论 :: 0 Trackbacks

#

在使用Netbeans的时候,除了Struts应用所需需要的Struts库文件与配置文件以外,创建一个Struts应用与
创建其他任何一个网络应用没有什么区别。其实创建一个Struts应用的方法和任何一个其他网络应用的方法
都一样。
  • 选择File > New Project. 在Categories里面选择Web。Projects项目下面,选择Web Application然后按Next。
  • 在输入项目名称和位置的面板里面,输入BBS作为项目名称,然后按Next;
  • 在服务器与设置面板里面,选择选择一个你准备用来deploy应用的服务器(如:GlassFish v2.1),同时注意面板下方的
    Context Path的路径与我们的项目名称一致,按Next;
  • 在Framework面板里,选择Struts

    将Application Resource里的名称com.myapp.struts.ApplicationResource改成com.bbs.struts.ApplicationResource .
  • 按下Finish,Struts的一个应用就建立完成了。
在项目管理器里面,所有的Struts指定的配置文件以及应用deploy所用的文件,都被放置在Configuration Files的目录里。
打开web.xml,我们可以看一下文件是如何管理Struts的。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
<servlet>
        
<servlet-name>action</servlet-name>
        
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        
<init-param>
            
<param-name>config</param-name>
            
<param-value>/WEB-INF/struts-config.xml</param-value>
        
</init-param>
        
<init-param>
            
<param-name>debug</param-name>
            
<param-value>2</param-value>
        
</init-param>
        
<init-param>
            
<param-name>detail</param-name>
            
<param-value>2</param-value>
        
</init-param>
        
<load-on-startup>2</load-on-startup>
        
</servlet>
    
<servlet-mapping>
        
<servlet-name>action</servlet-name>
        
<url-pattern>*.do</url-pattern>
    
</servlet-mapping>
    
<session-config>
        
<session-timeout>
            30
        
</session-timeout>
    
</session-config>
    
<welcome-file-list>
        
<welcome-file>index.jsp</welcome-file>
        
</welcome-file-list>
    
</web-app>

posted @ 2009-10-20 18:07 Chucky 阅读(195) | 评论 (0)编辑 收藏

到16节 和项目相关的东西,觉得已经没什么要写的了;基本还剩下一些css之类的页面设计和美化工作。
这方面没有什么感觉,总之把跟这个项目相关的东西放在一起(src和web相关的东西);有兴趣可以下来看看。
blog_servlet

Ok 跟blog_servlet相关的东西到这里结束了,下周开始做blog Struts相关的项目。

posted @ 2009-10-08 19:04 Chucky 阅读(103) | 评论 (0)编辑 收藏

     摘要: 对于表格数据处理的话,displayTag有很大的优势;但是有些时候还得自己动手做点工作; 我自己写了一个PageTag的类来处理一些简单的工作。 PageTag.java Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->&n...  阅读全文
posted @ 2009-10-07 18:58 Chucky 阅读(236) | 评论 (0)编辑 收藏

     摘要: 上一节谈了displaytag的基本用法,这一节就结合项目来看一下。按照常理,可能使用到displaytag的地方, 集中在管理页面里,譬如对博文的管理或者是针对comments的管理;相对而言category似乎并不需要使用分页; 很少会有人开几十个不同的分类吧 XD。 好吧,我们来比较一下,displaytag和原来的代码有什么不同。 这是原先的页面 网页的code: ...  阅读全文
posted @ 2009-10-07 16:37 Chucky 阅读(204) | 评论 (0)编辑 收藏

随着博文的增加或者评论的增加,是必要考虑一下分页问题。
在这个项目里,对于分页问题,我采取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两个选择。
  
 

posted @ 2009-10-05 17:07 Chucky 阅读(263) | 评论 (0)编辑 收藏

到11节基本的东西都已经实现了,剩下的都是一点细节问题;比如由于注册用户和普通浏览用户权限不同,所以大家看的也有所不同;
在项目设计的时候,普通用户可以看博客,发表评论;为了避免不必要的麻烦,将普通用户的操作特别的写一个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     }



posted @ 2009-10-05 16:26 Chucky 阅读(141) | 评论 (0)编辑 收藏

我们大家都有使用博客或者其他类似系统的经验,往往都是通过用户验证以后,才进行其他的操作。
上一节,在处理完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/");
   }
%>


posted @ 2009-09-30 16:47 Chucky 阅读(211) | 评论 (0)编辑 收藏

UserServlet主要用于用户登录,退出以及密码修改方面的事务。鉴于对网络应用的安全性考虑,
所以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     }


posted @ 2009-09-30 14:22 Chucky 阅读(199) | 评论 (0)编辑 收藏

为了让博文编辑更方便,这里介绍一下FCKeditor这个组件, 在这个项目里我们主要利用这个组件的工具栏
 

FCKeditor提供了很详细的文档,关于FCKeditor的安装,软件本身提供了对多种语言的支持,根据项目的需要,这里着重介绍javascript的安装方法。
首先在网页的表头添加下面的声明
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
接下来有3种不同的方法使用FCKeditor,
方法一. inline方式 在网页body部分,把编辑器放在你想放的地方(通常在表单里面),在该位置添加以下脚本:
<script type="text/javascript">
var oFCKeditor = new FCKeditor('FCKeditor1');
oFCKeditor.BasePath 
= "/fckeditor/";
oFCKeditor.Create();
</script>
方法一实例
<html>
<head>
<title>FCKeditor - Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex, nofollow">
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
</head>
<body>
<form>
<script type="text/javascript">
var oFCKeditor = new FCKeditor('FCKeditor1');
oFCKeditor.BasePath 
= "/fckeditor/";
oFCKeditor.Create();
</script>
</form>
</body>
</html>

方法二 替换TextArea方式
1.先在Head部位添加onload方法
<script type="text/javascript">
window.onload 
= function()
{
var oFCKeditor = new FCKeditor( 'MyTextarea' ) ;
oFCKeditor.BasePath 
= "/fckeditor/" ;
oFCKeditor.ReplaceTextarea() ;
}
</script>
2.在<body>部分 添加并替换原先的TextArea
<textarea id="MyTextarea" name="MyTextarea">This is <b>the</b> initial value.</textarea>
注意 textarea的名字和FCKeditor的对象名称一致

现在我们就可以使用一个很漂亮方便的工具栏了


但是在个漂亮的工具栏Font里面是没有宋体,黑体之类的中文字体的,所以在使用前,我们还要做一定的修改。
打开fckeditor/fckconfig.js,找到并修改FCKConfig.FontNames如下
FCKConfig.FontNames        = '宋体;黑体;隶书;楷体_GB2312;幼圆;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;

好了经过安装FCKeditor这个编辑器基本就可以使用了。
值得注意的是,FCKeditor的属性是case sensitive,所以在使用的时候千万注意。

posted @ 2009-09-29 17:16 Chucky 阅读(103) | 评论 (0)编辑 收藏

相对于上一篇的CategoryServlet,BlogServlet相对复杂一些。
不如在做添加博文的时候,我们要考虑的不仅仅是blog本身的主题,内容还要考虑blog所对应的类别;
一般我们把类别做成一个List以供选择。所以在blog添加的前,我们首先要处理category信息,那么
如果要添加blog的话,首先要做的是预处理category。
 1 private void preAdd(HttpServletRequest request, HttpServletResponse response)
 2             throws ServletException, IOException {
 3         List categories = null;
 4         String sql = "select id,name from category order by name";
 5         QueryRunner qr = DbHelper.getQueryRunner();
 6         try {
 7             categories = (List) qr.query(sql, new BeanListHandler(Category.class));
 8         } catch (SQLException ex) {
 9             Logger.getLogger(BlogServlet.class.getName()).log(Level.SEVERE, null, ex);
10         }
11         request.setAttribute("categories", categories);
12         request.getRequestDispatcher("/admin/addBlog.jsp").forward(request, response);
13     }
从code上看,预处理与blog类并没有关系,而是针对category的。

在list所有blog记录的时候,我们同样要考虑到category信息,
 1 private void list(HttpServletRequest request, HttpServletResponse response)
 2             throws ServletException, IOException {
 3         String sql = "select b.id as id,title,content,date,c.name as category, c.id as categoryId from blog b,category c where category_id=c.id order by b.date desc";
 4         QueryRunner qr = DbHelper.getQueryRunner();
 5         List blogs = null;
 6         try {
 7             blogs = (List) qr.query(sql, new BeanListHandler(Blog.class));
 8         } catch (SQLException ex) {
 9             Logger.getLogger(BlogServlet.class.getName()).log(Level.SEVERE, null, ex);
10         }
11         request.setAttribute("blogs", blogs);
12         request.getRequestDispatcher("/admin/adminBlogList.jsp").forward(request, response);
13     }
第3行的sql语句将blog表与category表关联起来,运行该SQL命令也成功找到相应的数据;但是在程序里,对应的JSP显示却不成功,与blog相关的数据正确,但是与categoryId对应的
category name(程序中的Blog类里的category)没有显示出来,数据显示是null。
这是因为DbUtils 在做表到对象的映射时要求列名和对象的属性名必须一致,也就是说对应blog类里的category属性正确的名称应该是name。
所以当
String sql = "select b.id as id,title,content,date,c.name as category, c.id as categoryId from blog b,category c where category_id=c.id order by b.date desc";
QueryRunner不能将数据映射到category属性里。在发现并解决了DbUtils项目的一个问题指出,问题的关键是DbUtils在处理数据表的时候是使用getColumnName()方法
BasicRowProcessor.java
 1 /** 
 2      * Convert a <code>ResultSet</code> row into a <code>Map</code>.  This 
 3      * implementation returns a <code>Map</code> with case insensitive column
 4      * names as keys.  Calls to <code>map.get("COL")</code> and 
 5      * <code>map.get("col")</code> return the same value.
 6      * @see org.apache.commons.dbutils.RowProcessor#toMap(java.sql.ResultSet)
 7      */
 8     public Map toMap(ResultSet rs) throws SQLException {
 9         Map result = new CaseInsensitiveHashMap();
10         ResultSetMetaData rsmd = rs.getMetaData();
11         int cols = rsmd.getColumnCount();
12 
13         for (int i = 1; i <= cols; i++) {
14             result.put(rsmd.getColumnName(i), rs.getObject(i));
15         }
16 
17         return result;
18     }
BeanProcessor.java
 1     /**
 2      * The positions in the returned array represent column numbers.  The 
 3      * values stored at each position represent the index in the 
 4      * <code>PropertyDescriptor[]</code> for the bean property that matches 
 5      * the column name.  If no bean property was found for a column, the 
 6      * position is set to <code>PROPERTY_NOT_FOUND</code>.
 7      * 
 8      * @param rsmd The <code>ResultSetMetaData</code> containing column 
 9      * information.
10      * 
11      * @param props The bean property descriptors.
12      * 
13      * @throws SQLException if a database access error occurs
14      *
15      * @return An int[] with column index to property index mappings.  The 0th 
16      * element is meaningless because JDBC column indexing starts at 1.
17      */
18     protected int[] mapColumnsToProperties(ResultSetMetaData rsmd,
19             PropertyDescriptor[] props) throws SQLException {
20 
21         int cols = rsmd.getColumnCount();
22         int columnToProperty[] = new int[cols + 1];
23         Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);
24 
25         for (int col = 1; col <= cols; col++) {
26             String columnName = rsmd.getColumnName(col);
27             for (int i = 0; i < props.length; i++) {
28 
29                 if (columnName.equalsIgnoreCase(props[i].getName())) {
30                     columnToProperty[col] = i;
31                     break;
32                 }
33             }
34         }
35 
36         return columnToProperty;
37     }
以上2段程序 读了就会发现问题所在了。DbUtils利用getColumnName()来处理列名,所以类似c.name as category, c.id as categoryId的语句并不适用与DbUtils。
解决的方法就是将以上2段程序中的getColumnName()方法改成getColumnLabel(),然后重新编译DbUtils源文件。然后将fixed的DbUtils文件重新加入库就可以解决问题了。
commons-dbutils-1.2_fixed.jar

BlogServlet中其他方法就不一一介绍了。





posted @ 2009-09-29 13:52 Chucky 阅读(115) | 评论 (0)编辑 收藏

仅列出标题
共4页: 上一页 1 2 3 4 下一页