蓝色部分请求转发代码为什么不跳转去list.jsp而是在原页面加入list.jsp的内容,这是什么原理
js代码$(function(){
$("#word").keyup(function()
//2。 获取输入框的值
//var word = $("#word").val();
//this 对应就是执行这个方法的那个对象, $("#word")
var word = $(this).val();
if(word == ""){
$("#div01").hide();
}else{
//3. 请求数据。
$.post("find",{word:word} ,function(data , status){
//alert(data);
$("#div01").show();
$("#div01").html(data);
});
}
})
});
servlet代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
try {
//1. 先获取参数
String word = request.getParameter("word");
System.out.println("word="+word);
//2. 让dao执行查询
WordsDao dao = new WordsDaoImpl();
List<WordBean> list = dao.findWords(word);
for (WordBean wordBean : list) {
System.out.println("==="+wordBean.toString());
}
request.setAttribute("list", list);
//3. 返回数据
response.setContentType("text/html;charset=utf-8");
//response.getWriter().write("数据是:");
request.getRequestDispatcher("list.jsp").forward(request, response);
} catch (SQLException e) {
e.printStackTrace();
}
}
list.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java. prefix="c"%>
<table style="width: 100%">
<c:forEach items="${list }" var="wordBean">
<tr>
<td>${wordBean.words}</td>
</tr>
</c:forEach>
</table>