public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String method=request.getParameter("method");
                if(method.equals("admin")){
admin(request, response);
}              
}
public void admin(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String sql="select id,name,level from sort order by level desc,id desc";
QueryRunner qr=dbSource.getQueryRunner();
List list=null;
try {
list=(List)qr.query(sql,new BeanListHandler(Sort.class));
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("list", list);
request.getRequestDispatcher("/adminSort.jsp").forward(request, response);
}
以上是Servlet里的代码,从数据库里查询数据 放入一个集合。Servlet测试了下应该是没有错的。接下来是JSP页面的,将得到的数据用for循环显示出来 结果一直给我报错误500
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: java.lang.ClassCastException: sun.misc.Sort cannot be cast to com.Rambo.Blog.Sort
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.Rambo.Blog.SortServlet.admin(SortServlet.java:53)
com.Rambo.Blog.SortServlet.doPost(SortServlet.java:35)
com.Rambo.Blog.SortServlet.doGet(SortServlet.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)关键是我改了将近一天了 还是找不到问题所在啊啊啊啊 气死人啊有木有!

解决方案 »

  1.   

    我勒个去,你这明显是 类型转换错误么sun.misc.Sort cannot be cast to com.Rambo.Blog.Sort
      

  2.   

    那咋办呢 我引用的是里面封装get set方法的Sort类。。把Sort改个名字?
      

  3.   


    那咋办呢 我引用的是里面封装get set方法的Sort类。。把Sort改个名字?
    [/Quote]  包导错了?
      

  4.   

    com.Rambo.Blog.Sort
    这个是你自己的,你在用的时候有没有导入正确的包?
    list=(List)qr.query(sql,new BeanListHandler(Sort.class));
    这里的Sort.class到底是什么包下面的?
    我可能怀疑是这里出问题!
      

  5.   


      包导错了?
    [/Quote]
    没导错  我确认了
      

  6.   


    没导错 是在com.Rambo.Blog包下的 
      

  7.   

    我把JSP的页面贴一下 大家帮忙来找找问题哈 不解决简直是心里一块疙瘩啊
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page import="com.Rambo.Blog.Sort" %>
    <%@ page import="java.util.List" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>分类管理</title>
    <style type="text/css">
    <!--
    .STYLE1 {
    font-family: "宋体";
    font-size: 24px;
    }
    .STYLE2 {font-size: 14px}
    -->
    </style>
    </head>
    <% List list=(List)request.getAttribute("list");
       Sort sort=null;
    %>
    <body>
    <script language=javascript> 
    function p_del() { 
    var msg = "您真的确定要删除吗?\n\n请确认!"; 
    if (confirm(msg)==true){ 
    return true; 
    }else{ 
    return false; 


    </script>
    <div align="center" class="STYLE1">分类管理<br /><br /></div>
    <div align="center">
        <table width="595" border="1">
          <tr>
            <td width="148" height="50"><div align="center" class="STYLE2">分类编号</div></td>
            <td width="277"><div align="center" class="STYLE2">分类名称</div></td>
            <td width="148"><div align="center" class="STYLE2">操作</div></td>
          </tr>
    <%  
    for(int i=0;i<list.size();i++){
    sort=(Sort)list.get(i);
    %>
          <tr>
           <td width="148" height="50"><div align="center" class="STYLE2"><%=sort.getId() %></div></td>
            <td width="277"><div align="center" class="STYLE2"><%=sort.getName() %></div></td>
            <td width="148"><div align="center" class="STYLE2">
            <a href="http://localhost/Blog/servlet/SortServlet?method=edit&id=<%=sort.getId() %>></a>">修改</a>
            /<a href="http://localhost/Blog/servlet/SortServlet?method=delete&id=<%=sort.getId() %>" onclick="javascript:return p_del()">删除</a></div></td>
          </tr>
          <% } %>
          </table>
    </div>
    </body>
    </html>
      

  8.   

    list=(List)qr.query(sql,new BeanListHandler(Sort.class));
    估计是这个导错了
    你把servlet的import贴进来,看看
      

  9.   

    sun.misc.Sort cannot be cast to com.Rambo.Blog.Sort 转型异常,你估计引错包了
      

  10.   


    真的是我竟然没发现自己啥时候把sun.misc.Sort导入了。。去掉就好了谢谢大家的热心 每人一个亲