论坛首页 Java企业应用论坛

学习笔记:获取XML数据,页面显示,实现详细信息与列表的联动效果

浏览 2669 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-12-27  
页面显示:
//加载数据岛
<xml id="xmldso_list" src="servlet/getXMLData"></xml>
    <b>用户详细信息:</b>
	<table bgcolor="#b5c7ef" style="font-size:12px;border:1px solid;width:80%">
		<tr align="left"><th width="20%">帐号:  </th><td id="td_account"></td><th width="20%">密码: </th><td id="td_password"></td></tr>
		<tr align="left"><th>部门名称: </th><td id="td_deptName"></td><th width="20%">用户名称: </th><td id="td_username"></td></tr>
		<tr align="left"><th>岗位名称:   </th><td id="td_postName"></td><th width="20%">创建时间: </th><td id="td_createtime"></td></tr>
		<tr align="left"><th>地址:</th><td id="td_Address"></td><th width="20%">备注: </th><td id="td_note"></td></tr>
	</table>
	<p><b>
	用户列表:
	</b><p><p><p></p>
	<div style="width:80%;height:200px;overflow:scroll;border:1px #9DBCEA solid;">
	<table datasrc="#xmldso_list" style="font-size:12px;" >
		<thead>
		<tr align="left"><th>帐号</th><th>部门名称</th><th>岗位名称</th><th>地址</th></tr>
		</thead>
		<tr align="left" onClick="testclick(this)" style="cursor: hand;"
		onmouseover="this.name=this.style.backgroundColor;this.style.backgroundColor='Honeydew';this.style.color='blue';" onmouseout="this.style.backgroundColor=this.name;this.style.color='black'">
		<td><div datafld="userAccount"></td>
		<td><div datafld="deptName"></td>
		<td><div datafld="postName"></td>
		<td align="right"><div datafld="address"></td>
		</tr>
	</table>
   </div>

js脚本
<script type="text/javascript">
	function testclick(field)
	{
		var row=field.rowIndex;
		xmldso_list.recordset.absoluteposition=row;
		td_account.innerHTML=xmldso_list.recordset("userAccount");
		td_deptName.innerHTML=xmldso_list.recordset("deptName");
		td_postName.innerHTML=xmldso_list.recordset("postName");
		td_Address.innerHTML=xmldso_list.recordset("address");
		td_password.innerHTML=xmldso_list.recordset("password");
		td_username.innerHTML=xmldso_list.recordset("username");
		td_createtime.innerHTML=xmldso_list.recordset("createtime");
		td_note.innerHTML=xmldso_list.recordset("note");
	}
	</script>

servlet获取数据
public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		List users = this.getSysmrgAccess().getUserList();
		
		response.setContentType("text/xml");
		response.setCharacterEncoding("gb2312");

		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control", "no-cache");

		PrintWriter out = response.getWriter();

		out.println("<?xml version=\"1.0\" encoding=\"gb2312\"?>");
		out.println("<users>");
		
		for(int i=0;i<users.size();i++)
		{
			PermUserAccount user = (PermUserAccount) users.get(i);
			out.println("<user>");
			out.println("<userAccount>"+user.getUserAccount()+"</userAccount>");
			out.println("<deptName>"+user.getDeptName()+"</deptName>");
			out.println("<postName>"+user.getPostName()+"</postName>");
			out.println("<address>"+user.getAddress()+"</address>");
			out.println("<password>"+user.getPassword()+"</password>");
			out.println("<username>"+user.getUserName()+"</username>");
			out.println("<createtime>"+user.getCreateTime()+"</createtime>");
			out.println("<note>"+user.getNote()+"</note>");
			out.println("</user>");
		}
		out.println(" </users>");
		out.flush();
		out.close();
	}


有啥意见尽管提,顺便作为学习笔记,免得以后忘了
  • 描述: 效果图
  • 大小: 837.3 KB
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics