ResearchAllCategory类中的一部分代码:
public String execute(){
try {
this.something();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
}
public void something() throws Exception{
if("class".equals(getFlag())){
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
response.setCharacterEncoding("UTF-8");
ActionContext.getContext().getSession();
System.out.println("next");
String flag=request.getParameter("flag");
out.println("<result>");
out.println("<flag>"+flag+"</flag>");
out.println("</result>");
}
}
js文件:
function init(){
send_request("ResearchAllCategory?flag=class&jumpPage=1");
}function send_request(url){
createXMLHttpRequest();
wait = document.getElementById("wait");
wait.innerHTML="<center>loading</center>";
wait.style.background ="yellow";
xmlHttp.onreadystatechange = callBack;
xmlHttp.open("get",url,true);
xmlHttp.send(null);}
function callBack(){
//alert(xmlHttp.readyState);
if(xmlHttp.readyState == 4){
alert(xmlHttp.status);
if (xmlHttp.status == 200) {
wait.innerHTML = "" ;
wait.style.background = "";
var flag=xmlHttp.responseXML.getElementsByTagName("flag")[0].firstChild.data;
alert(flag);
}
}
}
本人新手 请教如何在struts2的类文件中写XML 上边给我报“xmlHttp.status =500”错误 然后用ajax读出并输出到页面 还有就是struts2类文件中的变量都要SET GET 方法吗?
public String execute(){
try {
this.something();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
}
public void something() throws Exception{
if("class".equals(getFlag())){
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
response.setCharacterEncoding("UTF-8");
ActionContext.getContext().getSession();
System.out.println("next");
String flag=request.getParameter("flag");
out.println("<result>");
out.println("<flag>"+flag+"</flag>");
out.println("</result>");
}
}
js文件:
function init(){
send_request("ResearchAllCategory?flag=class&jumpPage=1");
}function send_request(url){
createXMLHttpRequest();
wait = document.getElementById("wait");
wait.innerHTML="<center>loading</center>";
wait.style.background ="yellow";
xmlHttp.onreadystatechange = callBack;
xmlHttp.open("get",url,true);
xmlHttp.send(null);}
function callBack(){
//alert(xmlHttp.readyState);
if(xmlHttp.readyState == 4){
alert(xmlHttp.status);
if (xmlHttp.status == 200) {
wait.innerHTML = "" ;
wait.style.background = "";
var flag=xmlHttp.responseXML.getElementsByTagName("flag")[0].firstChild.data;
alert(flag);
}
}
}
本人新手 请教如何在struts2的类文件中写XML 上边给我报“xmlHttp.status =500”错误 然后用ajax读出并输出到页面 还有就是struts2类文件中的变量都要SET GET 方法吗?
都有相应的set和get 方法