- 浏览: 123630 次
最新评论
-
gaoxikun:
看起来很齐全,很完美,但是不知道从哪里下载 。
myeclipse插件简单介绍 -
gaoxikun:
亲,能把这个集成了插件的myeclipse 6.5给我一下吗, ...
myeclipse插件简单介绍 -
hotsmile:
不错!!!!!!!!!
myeclipse插件简单介绍
package com.huawei.cmclient.common.config;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.huawei.cmclient.common.sys.SystemLoader;
import com.huawei.cmclient.common.utils.ParamChecking;
import com.huawei.cmclient.common.utils.UnifyUtils;
import com.huawei.cmclient.common.vo.tree.Tree;
import com.huawei.cmclient.common.vo.tree.TreeNode;
public class TreeConfig
{
private static final Map<String, Tree> treeMap = new HashMap<String, Tree>();
private String nodeConfigFile;
public static Map<String, Tree> getTreeMap()
{
return treeMap;
}
/**
* 读取配置文件
*/
public void init()
{
try
{
String cmClientPath = SystemLoader.getCmClientPath();
// File configFile = new File(cmClientPath + File.separator + nodeConfigFile.trim());
File configFile = new File("D://我的文档//workspace/CMClient//WebRoot//WEB-INF//conf//common//tree_config.xml");
SAXReader reader = new SAXReader();
Document document = reader.read(configFile);
parse(document);
}
catch (DocumentException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* 解析配置值
* @param document
* @throws Exception 抛出异常
*/
private void parse(Document document)
throws Exception
{
Tree tree = null;
TreeNode treeNode = null;
final Element root = document.getRootElement();
final List< ? > trees = root.elements("tree");
for (final Iterator< ? > iterator = trees.iterator(); iterator.hasNext();)
{
Element treeElement = (Element) iterator.next();
tree = new Tree();
parseTreeAttribute(tree, treeElement);
List< ? > nodes = treeElement.elements("node");
for (final Iterator< ? > iter = nodes.iterator(); iter.hasNext();)
{
final Element nodeElement = (Element) iter.next();
treeNode = new TreeNode();
parseNodeAttribute(treeNode, nodeElement);
parseNodeValue(treeNode,nodeElement);
tree.getNodeList().add(treeNode);
}
treeMap.put(tree.getId(), tree);
}
}
private void parseTreeAttribute(Tree tree, Element element)
{
//
final Attribute idAtt = element.attribute("id");
tree.setId("root");
if (null != idAtt && ParamChecking.isBlank(idAtt.getValue()))
{
tree.setId(UnifyUtils.processTrim(idAtt.getValue()));
}
final Attribute useArrowsAtt = element.attribute("useArrows");
if (null != useArrowsAtt && "false".equals(UnifyUtils.processTrim(useArrowsAtt.getValue())))
{
tree.getTreeOptions().setUseArrows(false);
}
}
private void parseNodeAttribute(TreeNode node, Element element)
{
final Attribute expanded = element.attribute("expanded");
if (null != expanded && "false".equals(expanded.getValue()))
{
node.getTreeNodeOptions().setExpanded(false);
}
}
private void parseNodeValue(TreeNode node, Element element)
{
org.dom4j.Node idNode = element.element("id");
org.dom4j.Node textNode = element.element("text");
org.dom4j.Node parentIdNode = element.element("parentId");
org.dom4j.Node methodNode = element.element("method");
node.setId(idNode.getText().trim());
node.setParentId(parentIdNode.getText().trim());
node.setText(textNode.getText().trim());
node.setMethod(methodNode.getText().trim());
}
/**
* @return Returns the nodeConfigFile.
*/
public String getNodeConfigFile()
{
return nodeConfigFile;
}
/**
* @param nodeConfigFile The nodeConfigFile to set.
*/
public void setNodeConfigFile(String nodeConfigFile)
{
this.nodeConfigFile = nodeConfigFile;
}
}
=====================================================================
package com.huawei.cmclient.common.action;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.rpc.holders.StringHolder;
import localhost.imsservice.services.CentrexService.Centrex;
import net.sf.json.JSONArray;
import org.apache.struts2.ServletActionContext;
import com.chinamobile.imsservice.centrex.datatype.holders.IntValueHolder;
import com.huawei.cmclient.common.config.TreeConfig;
import com.huawei.cmclient.common.utils.ParamChecking;
import com.huawei.cmclient.common.vo.tree.Tree;
import com.opensymphony.xwork2.ActionSupport;
public class BaseAction
extends ActionSupport
{
private static final long serialVersionUID = 1L;
private Centrex centrex;
private boolean success;
private String msg;
private String jsonString = "";
public HttpServletRequest getRequest()
{
return ServletActionContext.getRequest();
}
public HttpSession getSession()
{
return ServletActionContext.getRequest().getSession();
}
public ServletContext getApplication()
{
return ServletActionContext.getServletContext();
}
public HttpServletResponse getResponse()
{
return ServletActionContext.getResponse();
}
/**
* @return Returns the centrex.
*/
public Centrex getCentrex()
{
return centrex;
}
/**
* @param centrex The centrex to set.
*/
public void setCentrex(Centrex centrex)
{
this.centrex = centrex;
}
public String getJsonString()
{
return jsonString;
}
public void setJsonString(String jsonString)
{
this.jsonString = jsonString;
}
public void outJson(String xmlMessage)
{
HttpServletResponse response = getResponse();
response.setCharacterEncoding("UTF-8");
PrintWriter out = null;
try
{
out = response.getWriter();
out.write(xmlMessage);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public StringBuffer getJsonString(String root, Object obj, Map<String, String> param)
{
StringBuffer json = new StringBuffer();
json.append("{\"success\":" + true + ",\"" + root + "\":");
JSONArray array = JSONArray.fromObject(obj);
json.append(array.toString());
if (!ParamChecking.isEmpty(param))
{
for (Entry<String, String> entity : param.entrySet())
{
json.append(",\"");
json.append(entity.getKey());
json.append("\":\"");
json.append(entity.getValue() + "\"");
}
}
json.append("}");
return json;
}
public StringBuffer getJsonString(String[] roots, Object[] objs, Map<String, String> param)
{
StringBuffer json = new StringBuffer();
json.append("{\"success\":");
json.append(true);
for (int i = 0; i < roots.length; i++)
{
json.append(",\"");
json.append(roots[i]);
json.append("\":");
json.append(JSONArray.fromObject(objs[i]).toString());
}
if (!ParamChecking.isEmpty(param))
{
for (Entry<String, String> entity : param.entrySet())
{
json.append(",\"");
json.append(entity.getKey());
json.append("\":\"");
json.append(entity.getValue() + "\"");
}
}
json.append("}");
return json;
}
public String getJsonString(IntValueHolder resultcode, String returnDesc)
{
StringBuffer json = new StringBuffer();
if (resultcode == null || resultcode.value == null || resultcode.value.getValue() == null
|| resultcode.value.getValue() != 0)
{
json.append("{\"failure\":" + true + ",\"msg\":\"" + returnDesc.replaceAll("\n", "<br/>"));
}
else
{
json.append("{\"success\":" + true + ",\"msg\":\"" + returnDesc.replaceAll("\n", "<br/>"));
}
json.append("\"}");
return json.toString();
}
public String getJsonOtherErrorString()
{
StringBuffer json = new StringBuffer();
json.append("{\"failure\":" + true + ",\"msg\":\"" + "其它错误");
json.append("\"}");
return json.toString();
}
/**处理服务端的返回消息
* @param resultCode
* @param resultDesc
* @see
*/
public void processResult(IntValueHolder resultCode, StringHolder resultDesc)
{
this.success = true;
if (null == resultCode || null == resultCode.value || resultCode.value.getValue() != 0)
{
this.success = false;
}
this.msg = "     操作失败!      ";//修改返回成功消息时,IE6界面显示不全的问题,modi by zhouchen 2011-07-18
if (null != resultDesc && !ParamChecking.isBlank(resultDesc.value))
{
//修改返回成功消息时,IE6界面显示不全的问题,modi by zhouchen 2011-07-08
Map<String, String> paramMap = new HashMap<String, String>();
StringBuffer sBuffer = new StringBuffer();
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(resultDesc.value);
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
paramMap.put("resultDesc", sBuffer.toString());
String resultdesc = sBuffer.toString();
this.msg = resultdesc.replaceAll("\n", "<br/>       ");//modi by zhouchen 将回车换行符修改成空格 2011-7-12
}
}
/**处理服务端的返回消息
* @param resultCode
* @param resultDesc
* @see
*/
public void processResultOneNumber(IntValueHolder resultCode, StringHolder resultDesc)
{
this.success = true;
if (null == resultCode || null == resultCode.value || resultCode.value.getValue() != 110000)
{
this.success = false;
}
this.msg = "     操作失败!      ";//修改返回成功消息时,IE6界面显示不全的问题,modi by zhouchen 2011-07-18
if (null != resultDesc && !ParamChecking.isBlank(resultDesc.value))
{
//修改返回成功消息时,IE6界面显示不全的问题,modi by zhouchen 2011-07-08
Map<String, String> paramMap = new HashMap<String, String>();
StringBuffer sBuffer = new StringBuffer();
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(resultDesc.value);
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
sBuffer.append(" ");
paramMap.put("resultDesc", sBuffer.toString());
String resultdesc = sBuffer.toString();
this.msg = resultdesc.replaceAll("\n", "<br/>       ");//modi by zhouchen 将回车换行符修改成空格 2011-7-12
}
}
/**
* 获取工程的绝对路径
* @return String "http://ip:port/CMServer/"
* @see
*/
public String getUrl()
{
String http = getRequest().getScheme();
String ip = getRequest().getLocalAddr();
String contextPath = getRequest().getContextPath();
int port = getRequest().getServerPort();
StringBuffer urlStr = new StringBuffer();
urlStr.append(http).append("://").append(ip).append(":").append(port).append(contextPath)
.append("/");//File.separator
return urlStr.toString();
}
/**
* @return Returns the success.
*/
public boolean isSuccess()
{
return success;
}
/**
* @param success The success to set.
*/
public void setSuccess(boolean success)
{
this.success = success;
}
/**
* @return Returns the msg.
*/
public String getMsg()
{
return msg;
}
/**
* @param msg The msg to set.
*/
public void setMsg(String msg)
{
this.msg = msg;
}
public static void main(String[] args)
{
BaseAction base=new BaseAction();
TreeConfig config=new TreeConfig();
config.init();
Tree tree = TreeConfig.getTreeMap().get("root");
StringBuffer jsonBuffer = base.getJsonString("root", tree, null);
System.out.println(jsonBuffer);
}
}
===========================================================
public String init()
{
//如果没有登录,返回登录页面
Object userKey = super.getSession().getAttribute(LoginContext.USERKEY);
if (null == userKey)
{
return ERROR;
}
Tree tree = TreeConfig.getTreeMap().get("root");
StringBuffer jsonBuffer = super.getJsonString("root", tree, null);
super.getRequest().setAttribute("treeRoot", jsonBuffer.toString());
return SUCCESS;
}
==================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="team" extends="json-default">
<action name="addTeam" method="addTeam"
class="TeamServiceAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">success,msg</param>
</result>
</action>
<action name="deleteTeam" method="deleteTeam"
class="TeamServiceAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">success,msg</param>
</result>
</action>
<action name="modifyTeam" method="modifyTeam"
class="TeamServiceAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">success,msg</param>
</result>
</action>
<action name="checkTeam" method="checkTeam"
class="TeamServiceAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">
success,msg,groupID,groupNumber,serviceTeamsResp.*
</param>
</result>
</action>
<action name="addTeamMember" method="addTeamMember"
class="TeamServiceAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">success,msg</param>
</result>
</action>
<action name="deleteTeamMember" method="deleteTeamMember"
class="TeamServiceAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">success,msg</param>
</result>
</action>
<action name="checkTeamMember" method="checkTeamMember"
class="TeamServiceAction">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">
success,msg,groupNumber,teamId,leftDisabled,rightDisabled,teamUsersResp.*
</param>
</result>
</action>
</package>
</struts>
发表评论
-
java 中的文件读取信息
2013-03-11 08:56 1059import java.io.BufferedReader ... -
oracle结果集的操作信息
2013-03-04 16:22 914众所周知的几个结果集集合操作命令,今天详细地测试了一下,发现一 ... -
js正则表达式(二)
2013-01-09 11:20 886首先加个重要的东西 * ... -
java路径问题以及java对文件的基本操作信息
2012-12-19 14:09 9751.基本概念的理解 绝对 ... -
JS正则表达式
2012-11-15 17:10 853function isTrueName(s) { var pa ... -
java公用类
2012-11-15 17:05 865package cn.org.jshuwei.j2ee.uti ... -
java规范信息
2012-10-30 08:44 27891 一、判断选择题(每题1分) 1. 表达式要在低优先级操作符 ... -
java时间公用和StringUnitl以及java调用存储过程
2012-10-16 17:38 16161 构建存储过程的语句信息 /** * 从Fun ... -
jquery批量删除
2012-09-20 14:31 3390<%@ page language="java ... -
java操作execl文件(2003与2007不兼容问题)
2012-09-19 14:49 1477package com.huawei.bss.execlCom ... -
java操作execl文件
2012-09-19 08:53 988package com.huawei.bss.execlCom ... -
通过onkeypress和onkeydown事件禁用键盘中某些键
2012-09-17 15:09 954http://zywang.iteye.com/blog/70 ... -
properties的修改
2012-09-14 16:05 1012public static void modifyProper ... -
java学习的一点记录
2012-09-12 16:15 1236public class Tools { stati ... -
STRUTS2与JSON的LIST和MAP对象返回
2012-09-07 14:57 6686<%@ page language="java ... -
struts2 iterator双重叠迭取值
2012-09-05 18:08 1260•效果:Map<String,List<Derpa ... -
struts2多个配置文件的应用
2012-09-05 10:10 1076<!-- 定义Struts2的核心Filter --&g ... -
java中使用net.sf.json对json进行解析
2012-09-04 12:24 1023作者: http://zhangnet1.iteye.com/ ... -
XML的TreeConfig
2012-09-04 10:20 913/** * <?xml version=&qu ... -
sql在不同数据库查询前几条数据
2012-09-03 15:14 802sql在不同数据库查询前几条数据 1. ORACLE ...
相关推荐
JSON与struts2配套的架包,配置测试成功,此压缩包内仅包含相关的json包
该资源是使用struts2框架进行操作,返回json格式数据,前台通过ajax提交内容。
json+struts2的jar包
JSON+Struts2事例 JSON+Struts2事例 JSON+Struts2事例 JSON+Struts2事例 JSON+Struts2事例 JSON+Struts2事例 JSON+Struts2事例 JSON+Struts2事例
为了让大家更快的将Json与Struts2进行整合,收集了整合所需的所有jar包,直接可以下载使用。
struts2-json-plugin,Struts JSON插件
json_struts2实例 json_struts2实例
json2.4+struts2-json-plugin-2.3.4
struts2 json
自己整理的jquery+json+struts2异步传输的例子,包括异步提交form,异步传输json对象。
struts2与json整合,可进一步讨论
Struts2+Json+Android简单实现,StrutsJson为服务端代码,JSONDemo为Android端代码
这可以实现struts和json的整合 <struts> <package name="demo" extends="json-default"> <result type="json"/> </action> </struts>
如果是作为客户端的HTTP+JSON接口工程,没有JSP等view视图的情况下,使用Jersery框架开发绝对是第一选择。... Struts2返回JSON有两种方式:1.使用Servlet的输出流写入JSON字符串;2.使用Struts2对JSON的扩展。
json + struts2 + 80个JQuery 效果 个例子
利用AJAX传递JSON数组,后台struts2的action接收。 详细代码简单易懂。
struts2转换 json
json2+jsonplugin struts2整合ajax时,使用json时需要的jar包。。。。。。。。。。。。
androind http 请求 struts2 action 返回 json 数据 例子
当自己做出来时,感觉挺简单的,但想起自己刚开始做不会那会儿,真的挺悲哀的啊,在网上也搜了半天也没搜出个123,最终经过苦战终于做出来的,文档中重要部分都标红提示了,在此分享给童鞋们