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">
$.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;
}
希望能帮帮忙