关于struts2的问题
前台部分:
function doSendMessage() { var message = $('#message').val(); var account = $('#account').val(); if($.trim(message)=='') { return; } showProcess('正在发送,请稍后......'); var $strParams = {'sendType':'1','receiver':account,'data':{'content': message}}; $.post("<%=basePath%>/cgi/message_send.action", $strParams, function(data){ hideProcess(); showSTip("发送成功"); doHideDialog("messageDialog"); },"json"); }
public class Message implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private String key; private int sendType; private String Receiver; private long timestamp; private HashMap<String, String> data; public Message() { data = new HashMap<String, String>(); timestamp = System.currentTimeMillis(); } public String getKey() { return key; } public String get(String k) { return data.get(k); } public long getTimestamp() { return timestamp; } public void setTimestamp(long timestamp) { this.timestamp = timestamp; } public void setKey(String key) { this.key = key; } public void put(String k, String v) { data.put(k, v); } public void remove(String k) { data.remove(k); } public HashMap<String, String> getData() { return data; } public void setData(HashMap<String, String> data) { this.data = data; } public int getSendType() { return sendType; } public void setSendType(int sendType) { this.sendType = sendType; } public String getReceiver() { return Receiver; } public void setReceiver(String receiver) { Receiver = receiver; } @Override public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("{"key":"").append(key).append("","); buffer.append(""sendType":"").append(sendType).append("","); buffer.append(""Receiver":"").append(Receiver).append("","); buffer.append(""timestamp":"").append(timestamp).append("","); buffer.append(""data":{"); AtomicInteger connectionsCounter = new AtomicInteger(0); int size = data.keySet().size(); for (String key : data.keySet()) { if (connectionsCounter.get() == size - 1) { buffer.append(""" + key + "":"").append(data.get(key)).append("""); } else { buffer.append(""" + key + "":"").append(data.get(key)) .append("","); } connectionsCounter.incrementAndGet(); } buffer.append("}}"); return buffer.toString(); } public String toJsonString() { return toString(); } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
去掉那段toString()的方法map里面的key还是null
参数是肯定传过来了,看起来是你在处理数据的地方出错了,就是在第二段代码的toString方法里;无论你信不信,这段代码真丑陋。