JSON

structs2刚开始学习,用json时,遇到了问题,希望各位能帮忙解决

字号+ 作者:H5之家 来源:H5之家 2017-07-06 15:01 我要评论( )

以下是代码 : !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.3//EN http://struts.apache.org/dtds/struts-2.3.dtd inde

structs2刚开始学习,用json时,遇到了问题,希望各位能帮忙解决一下

json

以下是代码

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">



<action> <result>index.jsp</result> <result type="json"> <param>true</param> <param>false</param> </result> </action> </package> <!-- Add packages here -->

$.ajax({
type : "post",
url : "webchat!chat.action",
dataType : "json",
data : {
"message.owner" : owner,
"message.username" : username,
"message.words" : msg,
"lastIndex" : lastIndex
},
success : function(data) {
lastIndex = data.lastIndex;
if (owner == "") {
owner = data.message.owner;
}
$.each(data.msg, function(i, m) {
if (m.owner != owner) {
showMsg(m.username, m.words,
"recv");
}
});
},
error : function(XMLHttpRequest,
textStatus, errorThrown) {
alert("亲,请稍后刷新一下界面,服务器正在玩命重启中...");
clearInterval(auto);
}
});

package xjl;

import java.util.ArrayList;
import java.util.List;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import javax.servlet.http.HttpServletRequest;

import org.omg.PortableInterceptor.SUCCESSFUL;

import com.opensymphony.xwork2.ActionSupport;

public class Webchat extends ActionSupport {

private Message message; List<Message> messages = new ArrayList<Message>(); List<Message> msg = new ArrayList<Message>(); private int lastIndex; public Message getMessage() { return message; } public void setMessage(Message message) { this.message = message; } public List<Message> getMessages() { return messages; } public void setMessages(List<Message> messages) { this.messages = messages; } public List<Message> getMsg() { return msg; } public void setMsg(List<Message> msg) { this.msg = msg; } public int getLastIndex() { return lastIndex; } public void setLastIndex(int lastIndex) { this.lastIndex = lastIndex; } @Override public String execute() { int n = messages.size(); if (lastIndex != -1) { for (int i = lastIndex + 1; i < n; i++) { msg.add(messages.get(i)); } } lastIndex = n - 1; System.out.println(lastIndex); if (message != null && !message.getWords().equals("")) { messages.add(message); } return SUCCESS; }

}

package xjl;

public class Message {
private String owenr;
private String username;
private String words;

public String getOwenr() { return owenr; } public void setOwenr(String owenr) { this.owenr = owenr; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public void setWords(String words) { this.words = words; } public String getWords() { return words; }

}

希望能帮帮忙

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 北京迈吉可迪特信息技术有限公司 D3.js学习笔记11

    北京迈吉可迪特信息技术有限公司 D3.js学习笔记11

    2017-07-06 09:00

  • 【W3s学JSON】JSON入门概念学习笔记

    【W3s学JSON】JSON入门概念学习笔记

    2017-07-03 12:02

  • 【SpringMVC学习09】SpringMVC与前台的jso

    【SpringMVC学习09】SpringMVC与前台的jso

    2017-07-02 17:00

  • JS Python Flask 处理json 学习笔记

    JS Python Flask 处理json 学习笔记

    2017-06-28 16:03

网友点评