老师,我的代码哪里错了?
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String basePath=request.getScheme()+"://"+request.getServerName()+":"+
request.getServerPort()+request.getServletContext().getContextPath()+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<style>
input{
width:300px;
height:30px;
}
#d1{
width:900px;
height:300px;
}
</style>
<body>
<center>
<input type="button" value="员工列表" onclick="a()">
<input type="button" value="职位列表" onclick="b()">
<input type="button" value="部门列表" onclick="c()">
<div id="d1">
</div>
</center>
</body>
<script type="text/javascript">
function a(){
//创建一个xmlrequest对象
var xmlhttp=new XMLHttpRequest();
//规定请求的类型 url 和 是否异步处理
xmlhttp.open("GET","<%=basePath%>EmpServlet?flag=1",true);
//将请求发送到服务器
xmlhttp.send();
//接受服务端响应 readyState=4 表示请求完成且响应已就绪 status=200表示请求响应一切正常
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyStatr==4 && xmlhttp.status==200){
document.getElementById("d1").innerHTML=xmlhttp.responseText;
}
}
}
function b(){
//创建一个xmlrequest对象
var xmlhttp=new XMLHttpRequest();
//规定请求的类型 url 和 是否异步处理
xmlhttp.open("GET","<%=basePath%>EmpServlet?flag=2",true);
//将请求发送到服务器
xmlhttp.send();
//接受服务端响应 readyState=4 表示请求完成且响应已就绪 status=200表示请求响应一切正常
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyStatr==4 && xmlhttp.status==200){
document.getElementById("d1").innerHTML=xmlhttp.responseText;
}
}
}
function c(){
//创建一个xmlrequest对象
var xmlhttp=new XMLHttpRequest();
//规定请求的类型 url 和 是否异步处理
xmlhttp.open("GET","<%=basePath%>EmpServlet?flag=3",true);
//将请求发送到服务器
xmlhttp.send();
//接受服务端响应 readyState=4 表示请求完成且响应已就绪 status=200表示请求响应一切正常
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyStatr==4 && xmlhttp.status==200){
document.getElementById("d1").innerHTML=xmlhttp.responseText;
}
}
}
</script>
</html>21
收起
正在回答
3回答
这个单词拼错了,应该是readyState,最后的r改成e,三个都改过来就可以运行了。<script>标签里写代码如果出现错误是没有提示的。祝学习愉快!

我没跑啊
2018-06-02 18:24:37
package com.a;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class EmpServlet
*/
@WebServlet("/EmpServlet")
public class EmpServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String flag=request.getParameter("flag");
String data="";
if("1".equals(flag)) {
data="小红<br>小明<br>小白";
}else if("2".equals(flag)) {
data="职员<br>经理";
}else if("3".equals(flag)) {
data="人事部<br>技术部<br>后勤部";
}
response.getOutputStream().write(data.getBytes("utf-8"));
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星