<%@ page language= "java" contenttype= "text/html; charset=utf-8"
pageencoding= "Utf-8"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd";
<meta http-equiv= "Content-type" content= "text/html; charset=utf-8";
<title >insert title here</title>
<body>
<script type= "Text/javascript";
$j. GetScript ("${teamcitypluginresourcespath}js/jquery-1.11.2.min.js");
its = {
Writeselect:function (obj) {
obj.options[0].selected = "select";
Obj.options[0].text = Obj.options[0].text
+ string.fromcharcode (event.keycode);
Event.returnvalue = false;
return obj.options[0].text;
},
Ttt:function () {
var ss = document.getElementById ("platform"). Value;
var JG = "";
if (ss = = ") {
var aas = Writeselect (document.getElementById (" platform "));
JG = AAS;
} else {
JG = document.getElementById ("platform"). Value;
}
Alert (JG);
},
Getallcases:function () {
var Path=document.getelementbyid ("path"). Value;
var xmlhttp;
if (window. XMLHttpRequest) {
//code for ie7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest ();
}else{//code for IE6, IE5
xmlhttp=new activexobject ("Microsoft.XMLHTTP");
}
if (xmlhttp==null) {
alert (' Your browser don not ajax! ');
return;
}
Var url= '/testjsajax/getcases.do ';
Xmlhttp.open ("POST", url,true);
Xmlhttp.setrequestheader ("Content-type", "Application/json"); //can ' t be application/json,charset=utf-8
Xmlhttp.send (path);
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==1| | xmlhttp.readystate==2| | xmlhttp.readystate==3) {
//local hint: load in/Process
}
if (xmlhttp.readystate==4 && xmlhttp.status==200) { br> var D=xmlhttp.responsetext; return value
//Processing return value
}
}
}
}
</script>
<input type= "text" id= "path" ></input><input type= "button" onclick= "Its.getallcases ()" ></input >
</body>
Service-side processing:
Public class Ajaxcontroller extends httpservlet{
protected void DoPost (HttpServletRequest req, HttpServletResponse resp)
throws Servletexception, IOException {
String path = (String) req.getattribute ("path") ;// the path ' s value would be null
stringbuffer JB = new StringBuffer ();
String line = null;
try {
BufferedReader reader = Req.getreader ();
while (line = Reader.readline ())! = null)
Jb.append (line),
} catch (Exception e) {/* Report an error */
}
Cas Emng casemng = new Casemng ();
Boolean update =casemng.updaterepository ("C:/TEST_SVN");
String cases = casemng.getallcases (jb.tostring ());
//jsonobject jsonobj = new Jsonobject ();
//jsonobj.put ("path", path);
Map map = new HashMap ();
System.out.println (cases);
Map.put ("cases", cases);
Gson Gson = new Gson ();
String jsonobj = Gson.tojson (map);
System.out.println ("cases:" +cases);
This.sendjson (resp, jsonobj);
}
public void Sendjson (httpservletresponse response, String jsonobj) {
try {
PrintWriter out = Response.getwriter ();
Out.print (Jsonobj);
Out.flush ();
Out.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
}
; charset=utf-8
Native JavaScript sends AJAX requests and server-side processing