Request Page request.jsp
Copy Code code as follows:
<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 "
pageencoding= "Iso-8859-1"%>
<! 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>
<script language= "JavaScript" ><!--
function Getxmlhttpobject () {
var xmlHttp = null;
try{
XmlHttp = new XMLHttpRequest ();
}catch (e) {
try{
XmlHttp = new ActiveXObject ("Msxml2.xmlhttp");
}catch (e) {
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function ShowMsg (str) {
XmlHttp = Getxmlhttpobject ();
if (xmlHttp = = null) {
Alert ("You browser don ' t support the Ajax");
Return
}
var url = "Response.jsp";
url = url + "? q=" + str;
url = url + "&sid =" + Math.random ();
Xmlhttp.onreadystatechange = statechanged;
Xmlhttp.open ("Get", url, True);
Xmlhttp.send (NULL);
}
function statechanged ()
{
if (xmlhttp.readystate==4)
{
document.getElementById ("Showhint"). InnerHTML = Xmlhttp.responsetext;
}
}
--></script>
<body>
<form name= "Form1" action= "" method= "POST" >
<p>RocarsId:</p>
<select name= "Select1" onchange= showmsg (Document.form1.select1.options[document.form1.select1.selectedindex) . Value) ">
<option value= "140" >140</option>
<option value= ">150</option>"
</select>
<div id= "Showhint" >show rocars ccrn messages.</div>
</form>
</body>
response.jsp
Copy Code code as follows:
<%@ page language= "java" contenttype= "Text/plain; Charset=utf-8 "
pageencoding= "UTF-8"%>
<%@ page import= "com.lwf.eus.util.*,java.util.*,com.lwf.eus.entity.*,com.lwf.eus.bean.*"%>
<title>response the Ccrn</title>
<body>
<%
String q = request.getparameter ("q");
SYSTEM.OUT.PRINTLN ("message:" + Q);
Rocarsbean rocars = Rocarsentity.getrocarslistbyid (q);
%>
<table>
<tr>
<td>RocarsId</td>
<td>RocarsCcrn</td></tr>
<tr>
<td><%=rocars.getrocarsid ()%></td>
<TD><%=ROCARS.GETCCRN ()%></td>
</tr>
</table>
</body>
Notice here and self-study practice a different is, request.jsp page with a div to display information, response.jsp from the database query out content in the Table tab, other HTML tags will not be displayed in the Div.