首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

easyui datagrid 指定servlet路径有关问题

2013-08-04 
easyui datagrid 指定servlet路径问题[sizesmall]JSP代码[/size]%@ page languagejava contentType

easyui datagrid 指定servlet路径问题
[size=small]JSP代码[/size]
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>datagrid 测试</title>
<!-- 加载 jquery -->
<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<!-- 加载 esayUI  -->
<link rel="stylesheet" type="text/css" href="../css/easyui.css"> 
<link rel="stylesheet" type="text/css" href="../css/icon.css"> 
<link rel="stylesheet" type="text/css" href="../css/demo.css">
<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/easyloader.js"></script>

<script type="text/javascript">
$(function(){
loadMessage();

});
function loadMessage(){

//加载数据 

  $('#a').datagrid({  

      url:'http://localhost:8080/BXpro/servlet/BranchSerDatagridDemo',  

      columns:[[  
  {field:'UID',title:'用户ID',width:100},
          {field:'ID',title:'主键ID',width:100},  
          {field:'BNAME',title:'部门',width:100}  
     ]]  

});
  
}
</script>
</head>
<body>
<div style="margin-top:100px;">
<table id="a" ></table>
</div>

</body>
</html>

servlet 代码

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
//String id = request.getParameter("id");
//String bname = request.getParameter("bname");
//System.out.println(id+":"+bname);

Dao dao = new Dao();
Object o []= new Object[0];

List<Map> list = dao.doquery("select * from branch", o);
System.out.println("list------"+list);
//输出  list------[{UID=1, ID=1, BNAME=行政部}, {UID=1, ID=2, BNAME=软件产品事业部}, {UID=1, ID=3, BNAME=市场部}, {UID=1, ID=4, BNAME=销售部}, {UID=1, ID=6, BNAME=管理部}]
if(list != null){

out.print(list);
//response.encodeURL("/test/datagridDemo.jsp");

}


}


DAO代码

public List <Map> doquery(String sql,Object...o){
List list = new ArrayList();
//1、获取数据库连接
DbmysqlConn dbmysql = new DbmysqlConn();
c = dbmysql.getConn();
//2、将SQL作为preparedStatement 参数传入
try {
ps = c.prepareStatement(sql);
setprepareValue(ps,o);      //给PS赋值
rs= ps.executeQuery();
//获取字段列数
rsm= rs.getMetaData();
int count = rsm.getColumnCount();
/*遍历出列数,列的值
  * key :字段的名称
  * value:字段的值
  */
while(rs.next()){
Map map = new HashMap();
for(int i=1;i<=count;i++){
map.put(rsm.getColumnName(i).toUpperCase(), rs.getObject(rsm.getColumnName(i)));
}
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
//释放资源
close(rs,ps,c);
}

return list;
}


但是没有查询出数据是怎么回事?第一次使用easyui datagrid  指定servlet路径,请大家指教下。。。。

热点排行