javascript|js|xml| objects
The XMLHTTP object can be used to pass parameters without refreshing the page, as a way for JavaScript to pass parameters to the JSP.
Here's an example of JavaScript passing parameters to a JSP:
xmlhttp.jsp
<%@ page contenttype= "text/html; charset=gb2312 "language=" java import= "java.util.*" import= "java.sql.*"%>
<script language= "JavaScript" >
function func ()
{
XML = new ActiveXObject ("Microsoft.XMLHTTP");
var post= "<input type= ' text ' name= ' name ' value= ' 1value '/>";//construct the data to carry
Xml.open ("Post", "xmlhttp.jsp", false);//Use the POST method to open a connection to the server and communicate asynchronously
Xml.setrequestheader ("Content-length", post.length);
Xml.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xml.send (post);//Send data
return results
var v = xml.responsetext;
Deal with this result
document.write (' Result: ' + V ');
}
</script>
<body >
<%
Out.println ("ABCD");
Java.io.BufferedReader br = Request.getreader ();
String str = "";
String Srt=br.readline ();
while (Srt!=null)
{
STR + + srt+ "\ n";
Srt=br.readline ();
}
Out.println (str);
%>
</body>
This means that the parameter "<input type= ' text ' name= ' name ' value= ' 1value '/> ' can be passed to this page to display a text box on the page. Of course you can also pass an XML file so you need to parse the XML file in the server-side code to get the parameters you need
You can pass parameters to any page, just change the Xml.open ("POST", "xmlhttp.jsp", false), and the xmlhttp.jsp for your target page will be URL.
It should be noted that in the lower version of Tomcat will report the error of read time out, this is the reason for Tomcat, a higher version of the problem can be solved