Struts2树状菜单实现Word下载.docx

上传人:b****5 文档编号:19056395 上传时间:2023-01-03 格式:DOCX 页数:10 大小:18.51KB
下载 相关 举报
Struts2树状菜单实现Word下载.docx_第1页
第1页 / 共10页
Struts2树状菜单实现Word下载.docx_第2页
第2页 / 共10页
Struts2树状菜单实现Word下载.docx_第3页
第3页 / 共10页
Struts2树状菜单实现Word下载.docx_第4页
第4页 / 共10页
Struts2树状菜单实现Word下载.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

Struts2树状菜单实现Word下载.docx

《Struts2树状菜单实现Word下载.docx》由会员分享,可在线阅读,更多相关《Struts2树状菜单实现Word下载.docx(10页珍藏版)》请在冰豆网上搜索。

Struts2树状菜单实现Word下载.docx

%@taglibprefix="

sx"

/struts-dojo-tags"

%

 

Stringpath=request.getContextPath();

StringbasePath=request.getScheme()+"

:

//"

 

+request.getServerName()+"

"

+request.getServerPort()

+path+"

/"

;

html>

<

head>

sx:

head/>

basehref="

%=basePath%>

>

title>

TreeExample(Static)<

/title>

metahttp-equiv="

content-type"

content="

text/html;

charset=UTF-8"

scriptlanguage="

JavaScript"

type="

text/javascript"

dojo.event.topic.subscribe("

treeSelected"

functiontreeNodeSelected(node){

dojo.io.bind({

url:

"

s:

urlvalue='

/info/staticTreeAction.action'

/>

?

nodeId="

+node.node.title,

load:

function(type,data,evt){

vardivDisplay=dojo.byId("

displayIt"

);

divDisplay.innerHTML=data;

},

mimeType:

text/html"

});

/script>

/head>

body>

divid="

Pleaseclickonanynodeonthetree.

/div>

divstyle="

float:

left;

margin-right:

50px;

treelabel="

软件工程"

templateCssPath="

/struts/tree.css"

showRootGrid="

true"

showGrid="

treeSelectedTopic="

treenodelabel="

开发工具"

id="

grandchild1Id"

/>

c++"

grandchild2Id"

delphi"

grandchild3Id"

/sx:

treenode>

编程思想"

child2Id"

数据结构"

child3Id"

设计模式"

child4Id"

相关框架插件"

child5Id"

Dojo"

gChild1Id"

Hibernate"

gChild2Id"

tree>

/body>

/html>

******************************************************************************

2.动态树状菜单:

地址栏访问方法http:

8080/study3/tree/showDynamicTreeAction.action

具体需要如下文件:

struts2的类库文件即与struts2相关的包文件,web.xml,struts.xml,动态树状菜单的显示页面treeExampleDynamic.jsp,

辅助显示页面:

dynamicTreeSelect.jsp,动态Action类文件DynamicTreeSelectAction.java,

提供数据的Bean类文件:

Category.java,

所需要的包文件如下:

commons-fileupload-1.2.1.jar

freemarker-2.3.12.jar

web.xml配置文件

*****web.xml******************************************************************

xmlversion="

1.0"

encoding="

web-appversion="

2.4"

xmlns="

xmlns:

xsi="

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="

filter>

filter-name>

struts2<

/filter-name>

filter-class>

org.apache.struts2.dispatcher.FilterDispatcher

/filter-class>

/filter>

filter-mapping>

url-pattern>

/*<

/url-pattern>

/filter-mapping>

welcome-file-list>

welcome-file>

index.jsp<

/welcome-file>

/welcome-file-list>

/web-app>

在此struts.xml配置文件中我将动态树状菜单以及动态Ajax树状菜单的配置内容写在了这一个

配置文件中,其中动态树状菜单需要的action有dynamicTreeSelectAction,showDynamicTreeAction

动态Ajax树状菜单需要的action有dynamicTreeSelectAction,showDynamicAjaxTreeAction,

getNodes,这两个实例共用了提供数据的bean类文件Category.java文件.同时它们共用了

dynamicTreeSelectAction,但用于显示的Action类文件分别用了自己的Action类文件.

*******struts.xml***************************************************************

?

!

DOCTYPEstrutsPUBLIC

-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"

//struts.apache.org/dtds/struts-2.0.dtd"

struts>

packagename="

default"

extends="

struts-default"

namespace="

/tree"

actionname="

dynamicTreeSelectAction"

class="

com.zhang.study3.DynamicTreeSelectAction"

result>

/dynamicTreeSelect.jsp<

/result>

/action>

showDynamicTreeAction"

com.zhang.study3.ShowDynamicTreeAction"

/treeExampleDynamic.jsp<

showDynamicAjaxTreeAction"

/treeExampleAjaxDynamic.jsp<

getNodes"

com.zhang.study3.ShowAjaxDynamicTreeAction"

resulttype="

freemarker"

/treeExampleAjaxDynamic.ftl

/package>

/struts>

********treeExampleDynamic.jsp***************************************************

Showcase-UITagExample-TreeExample(Dynamic)<

/tree/dynamicTreeSelectAction.action'

+node.node.widgetId,

displayId"

treeid="

tree"

rootNode="

%{treeRootNode}"

childCollectionProperty="

children"

nodeIdProperty="

id"

nodeTitleProperty="

name"

Pleaseclickonanyofthetreenodes.

******dynamicTreeSelect.jsp***************************************************

%>

Id:

propertyvalue="

%{nodeId}"

br/>

Name:

%{nodeName}"

(注:

此文件就这三行代码负责将你选择的树状菜单相应结点信息如节点Id值与节点名称显示

在.jsp页面上.)

用于生成树状菜单的Action类文件

******DynamicTreeSelectAction.java********************************************

packagecom.zhang.study3;

importcom.opensymphony.xwork2.ActionSupport;

importcom.zhang.study3.Category;

publicclassDynamicTreeSelectActionextendsActionSupport{

privatelongnodeId;

privateCategorycurrentCategory;

publicvoidsetNodeId(longnodeId){

this.nodeId=nodeId;

}

publiclonggetNodeId(){

returnnodeId;

publicStringexecute()throwsException{

currentCategory=Category.getById(nodeId);

returnSUCCESS;

publicStringgetNodeName(){

returncurrentCategory!

=null?

currentCategory.getName():

Nodenotfound"

}

提供数据的bean类文件

****Category.java*************************************************************

importjava.util.ArrayList;

importjava.util.HashMap;

importjava.util.List;

importjava.util.Map;

publicclassCategory{

privatestaticMap<

Long,Category>

catMap=newHashMap<

();

static{

newCategory(1,"

省总公司"

newCategory(2,"

地市1分公司"

newCategory(3,"

桥东区办事处"

newCategory(4,"

市场组"

),

newCategory(7,"

客服组"

newCategory(8,"

技术组"

)),

newCategory(9,"

开发区办事处"

newCategory(10,"

newCategory(11,"

newCategory(12,"

newCategory(13,"

后勤组"

))),

newCategory(14,"

地市2分公司"

newCategory(15,"

软件开发组"

newCategory(16,"

软件测试组"

newCategory(17,"

售后服务组"

newCategory(18,"

市场拓展组"

newCategory(19,"

财物组"

)));

publicstaticCategorygetById(longid){

returncatMap.get(id);

privatelongid;

privateStringname;

privateList<

Category>

children;

private

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 其它考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1