jsp如何实现这个案例啊
有人用jsp做这个案例成功了吗?有的话可以分享给我参考看看吗
有人用jsp做这个案例成功了吗?有的话可以分享给我参考看看吗
2018-06-12
我也是刚刚看到这里,我只做了一个小的模仿,只做了第一小题的简化版,关键点在于前后端的数据是如何传递的,理解了第一题我觉得第二题肯定也不会太难做,希望能够帮到你。
这是后端的servlet代码,我写的很简单,希望不要嫌弃。


前端代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
window.onload=function(){
document.getElementById("username").onblur=function(){
var xmlhttp = null;
if(window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
else
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", "http://localhost:8080/myfirstwebapp/cat?username="+document.getElementById("username").value.toString());
xmlhttp.send();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState==4&&xmlhttp.status==200)
document.getElementById("queryUserName").innerHTML = xmlhttp.responseText;
};
}
document.getElementById("username").onfocus=function(){
document.getElementById("queryUserName").innerHTML = "";
}
}
</script>
</head>
<body>
<h2 style="color:red;">测试ajax程序</h2>
<form action="">
用户名:<input id="username" type="text" name="username">
<span id="queryUserName" style="color:red;"></span>
</form>
</body>
</html>
举报