问题描述
- structs2刚开始学习,用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 name="webchat" class="xjl.Webchat"> <result name="chat">index.jsp</result> <result name="success" type="json"> <param name="noCache">true</param> <param name="ignoreHierarchy">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; }
}
希望能帮帮忙
解决方案
只有代码,你要问什么问题呢?是报错了还是怎么的
解决方案二:
首先,你得告诉我报错内容是什么
第二,你的json,没啥没有在execute方法里转呢,没有转成json串,它怎么传到前台啊啊啊啊
解决方案三:
帮忙解决一下,谢谢了