课程打卡,请老师帮忙检查,谢谢
来源:2-8 自由编程
慕莱坞4341820
2020-10-17 14:20:49
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.container{
width: 100%;
}
input {
width: 33%;
}
#result {
width: 100px;
margin: 10px auto;
}
ul {
list-style: none;
text-align: center;
}
</style>
</head>
<body>
<div class="containter">
<input type="button" id="employee" name="employee" value="员工列表" /> <input
type="button" id="position" name="position" value="职位列表" /> <input
type="button" id="department" name="department" value="部门列表" />
<ul id="result">
</ul>
</div>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript">
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
$("input[type=button]").click(function(event) {
var name = $(this).attr("name");
xmlHttp.open("GET", "/jquery/job?name=" + name, true);
xmlHttp.send();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var text = xmlHttp.responseText;
$("#result").html(text);
}
}
})
</script>
</body>
</html>
在这里输入代码,可通过选择【代码语言】突出显示
------------------------------------------------------------------------------------------------------
/**
* Servlet implementation class jobServlet
*/
@WebServlet("/job")
public class jobServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public jobServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String category = request.getParameter("name");
String result = "";
switch(category) {
case "employee":
result = "<li>小红</li><li>小明</li><li>小白</li>";
break;
case "position":
result = "<li>职员</li><li>经理</li>";
break;
case "department":
result = "<li>人事部</li><li>技术部</li><li>无线事业部</li>";
break;
}
response.setContentType("text/html;charset=UTF-8");
response.getWriter().println(result);
}
}
1回答
同学你好,测试代码完成的不错,很棒,继续加油
祝学习愉快
相似问题