「javajsp树」java实现树的方式
今天给各位分享javajsp树的知识,其中也会对java实现树的方式进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java,jsp带checkbox的树形菜单,如何实现?
- 2、java,jsp实现组织树部门
- 3、如何用jsp做个树形下拉框??
- 4、JSP实现论坛树型结构的具体算法
- 5、如何在Java Jsp页面中动态生成树
- 6、如何用java与jsp实现树形结构
java,jsp带checkbox的树形菜单,如何实现?
jsp中带有checkbox的属性菜单需要用easyui组件来实现,代码如下:
!DOCTYPE html
html
head
meta charset="UTF-8"
titleCheckBox Tree - jQuery EasyUI Demo/title
link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"
link rel="stylesheet" type="text/css" href="../../themes/icon.css"
link rel="stylesheet" type="text/css" href="../demo.css"
script type="text/javascript" src="../../jquery.min.js"/script
script type="text/javascript" src="../../jquery.easyui.min.js"/script
/head
body
h2CheckBox Tree/h2
pTree nodes with check boxes./p
div style="margin:20px 0;"
a href="#" class="easyui-linkbutton" onclick="getChecked()"GetChecked/a
/div
div style="margin:10px 0"
input type="checkbox" checked onchange="$('#tt').tree({cascadeCheck:$(this).is(':checked')})"CascadeCheck
input type="checkbox" onchange="$('#tt').tree({onlyLeafCheck:$(this).is(':checked')})"OnlyLeafCheck
/div
div class="easyui-panel" style="padding:5px"
ul id="tt" class="easyui-tree" data-options="url:'tree_data1.json',method:'get',animate:true,checkbox:true"/ul
/div
script type="text/javascript"
function getChecked(){
var nodes = $('#tt').tree('getChecked');
var s = '';
for(var i=0; inodes.length; i++){
if (s != '') s += ',';
s += nodes[i].text;
}
alert(s);
}
/script
/body
/html
运行效果:
java,jsp实现组织树部门
jeesite吧
views/models/sys/officeIndex.jsp
里面的js代码你可以学习学习,直接拿来用就好
如何用jsp做个树形下拉框??
用jsp做树形下拉框可以用java自定义标签实现。
参考代码如下:
package com.moonNigh.tagSupport;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/**
*
*
* 树形下拉选择控件
*
*/
public class SelectorTag extends TagSupport {
private static final long serialVersionUID = 9878861374414215L;
//标签name属性
private String name;
//所需图片的路径
private String imgPath;
//所需javascript文件的路径
private String scriptPaht;
//所需css文件的路径
private String cssPath;
//项目的根路径
private String rootPath;
//标签的value属性
private String value;
private String text;
private String path;
/*
* 标签的actionUrl属性
* 联想查询结果数据通过向actionUrl属性指定的url请求得到
*/
private String actionUrl;
private HttpServletRequest request=null;
public String getActionUrl() {
return actionUrl;
}
public void setActionUrl(String actionUrl) {
this.actionUrl = actionUrl;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
public String getScriptPaht() {
return scriptPaht;
}
public void setScriptPaht(String scriptPaht) {
this.scriptPaht = scriptPaht;
}
public String getCssPath() {
return cssPath;
}
public void setCssPath(String cssPath) {
this.cssPath = cssPath;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public SelectorTag()
{
}
/**
* 初始化变量
*/
private void initAbttributes()
{
request=(HttpServletRequest)this.pageContext.getRequest();
rootPath=request.getContextPath();
this.imgPath="/images/";
this.scriptPaht="/js/";
this.cssPath="/css/";
}
@Override
public int doStartTag() throws JspException {
initAbttributes();
path=rootPath+"/jsp/tags/treeSelectorPage.jsp?id="+id+"actionUrl="+actionUrl;
JspWriter out=pageContext.getOut();
try {
String tName=name;
//引入javascript文件
out.println("script type='text/javascript' charset='GB2312' src='"+rootPath+scriptPaht+"selector.js'/script");
//引入css文件
out.println("link rel='stylesheet' href='"+rootPath+cssPath+"selector.css' type='text/css' /");
StringBuilder tag=new StringBuilder("input type='text' ");
tag.append("id='").append(id).append("'");
tag.append(" value='").append(text==null?"":text).append("'");
tag.append(" onclick='return showSelector(\"");
tag.append(id).append("\",\"").append(path).append("\")' readonly");
tag.append("input type='hidden' name='")
.append(tName).append("' id='").append(id).append("_value")
.append("' value='").append(value==null?"":value).append("'");
out.println(tag.toString());
} catch (IOException e) {
e.printStackTrace();
}
return SKIP_BODY;
}
}
运行结果:
JSP实现论坛树型结构的具体算法
实现论坛树型结构的算法很多 具体你可以去 chinaasp 的全文搜索中查询 我现在的JSP论坛采用的也是当中的一种 不用递归实现树型结构的算法 现在我将论坛树型结构的具体算法和大家介绍一下 和大家一起交流
演示表的结构 表名 mybbslist 字段 数据类型说明 BBSID自动编号 RootID Int 根帖ID 本身为根帖则RootID = ID FID Int 父帖ID 上一层帖子的ID 如是根帖则FID = DEPTHInt 根帖Level= 其他依据回复的深度递增 BBSSubject Char主题
创建表
create table mybbslist ( forumID int( ) not null bbsID int auto_increment primary key rootid int( ) not null fid int( ) not null depth int( ) not null userID int( ) not null bbsUser varchar( ) not null bbsSubject varchar( ) not null bbsContent text bbsTime varchar( ) bbsRead int( ) bbsReply int( ) INDEX forumID (forumID))
连接MYSQL数据库的BEAN
package netzero; import java sql *; public class mydb { String driverName = " gjt mm mysql Driver"; Connection conn = null; Statement stmt = null; ResultSet rs = null; String connURL= "jdbc:mysql://localhost/mybbs?user=rootpassword=howuseUnicode=truecharacterEncode= _ "; //String connURL= "jdbc:mysql://localhost/netzerobbs?user=rootpassword=how"; public mydb() { try { Class forName(driverName); } catch (java lang ClassNotFoundException e) { System err println("netzero(String): " + e getMessage()); } }
public ResultSet executeQuery(String sql) throws SQLException { conn = DriverManager getConnection(connURL); stmt = conn createStatement(); rs = stmt executeQuery(sql); return rs; }
public boolean closeConn() { try { if (rs!=null) rs close(); if (stmt!=null) stmt close(); if (conn!=null) conn close(); return true; } catch ( SQLException ex ) { System err println("closeConn: " + ex getMessage()); return false; } }
}
显示论坛的JSP程序
<jsp:useBean id="mybbs" scope="session" class="netzero mydb" /> <%@ page contentType="text/;charset=gb " %> <%@ page import="java io *" %> <%@ page import="java sql *" %> <% int intRowCount; out print("显示论坛树形结构"); out print("<br><br>"); try { String sql="select * from mybbslist order by rootid desc depth fid bbsid"; ResultSet rs = mybbs executeQuery(sql); if (rs next()) { rs last(); intRowCount=rs getRow(); out print("论坛树中有"); out print(intRowCount); out print("个叶子节点"); rs first(); int j= ; int Depth = ; out print("<ul>"); while(j<intRowCount) { int rsDepth=rs getInt("Depth"); if (rsDepth<Depth) { for(int i= ;i<Depth+ ;i=i+ ) { out print("</ul>"); } } rsDepth=rs getInt("Depth"); if (rsDepth>Depth) { out print("<ul>"); } out print("<li>");
String bbssubject=rs getString("bbssubject"); out print(bbssubject); out print("</li>"); Depth = rs getInt("Depth"); j=j+ ; rs next(); } out print("</ul>"); } else { out print("数据库中无记录"); } }catch (SQLException E) { out println("SQLException: " + E getMessage()); out println("SQLState: " + E getSQLState()); out println("VendorError: " + E getErrorCode()); } %> <% //关闭mysql连接 try { if(!mybbs closeConn()); } catch (Exception ex) { System err println("closeConn: " + ex getMessage()); } %>
lishixinzhi/Article/program/Java/JSP/201311/20347
如何在Java Jsp页面中动态生成树
JSP
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""
html
head
titleDestroydrop » Javascripts » Tree/title
link rel="StyleSheet" href="dtree.css" mce_href="dtree.css" type="text/css" /
mce:script type="text/javascript" src="dtree.js" mce_src="dtree.js"/mce:script
/head
body
h1a href="/" mce_href=""Destroydrop/a » a href="/javascripts/" mce_href="javascripts/"Javascripts/a » a href="/javascripts/tree/" mce_href="javascripts/tree/"Tree/a/h1
h2Example/h2
div class="dtree"
pa href="javascript: d.openAll();" mce_href="javascript: d.openAll();"open all/a | a href="javascript: d.closeAll();" mce_href="javascript: d.closeAll();"close all/a/p
mce:script type="text/javascript"!--
d = new dTree('d');
d.add(0,-1,'My example tree');
d.add(1,0,'Node 1','example01.html');
d.add(2,0,'Node 2','example01.html');
d.add(3,1,'Node 1.1','example01.html');
d.add(4,0,'Node 3','example01.html');
d.add(5,3,'Node 1.1.1','example01.html');
d.add(6,5,'Node 1.1.1.1','example01.html');
d.add(7,0,'Node 4','example01.html');
d.add(8,1,'Node 1.2','example01.html');
d.add(9,0,'My Pictures','example01.html','Pictures I/'ve taken over the years','','','img/imgfolder.gif');
d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
d.add(11,9,'Mom/'s birthday','example01.html');
d.add(12,0,'Recycle Bin','example01.html','','','img/trash.gif');
document.write(d);
// --/mce:script
/div
pa href="mailto:drop@destroydrop.com" mce_href="mailto:drop@destroydrop.com"©2002-2003 Geir Landrö/a/p
/body
/html
如何用java与jsp实现树形结构
你这个不是技术上的问题.
是你自己来没有理清逻辑关系,
简单的来说,就是要在相应的位置一输出相应的数据.
但这个数据怎么来构建,之间的关系如何建立,这个就需要你自己来做了.
你这个说,没有人能想出具体的情况.
只能说可以实现.
具体的,就没有办法帮你了.
关于javajsp树和java实现树的方式的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。