<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="WEB-INF/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
function load(){
$("#text01").load("DemoServlet02",function(responseText , statusTXT , xhr) {
//找到id为text02的元素, 设置它的value属性值为 responseText 对应的值
$("#text01").val(responseText);
});
}
</script>
</head>
<body>
<h3><input type="button" onclick="load()" value="使用JQuery执行load方法"></h3>
<input type="text" id="text01">
</body>
</html>
上面是jQueryDemo.jsp页面
package com.xhxy.Servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DemoServlet02 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("收到了请求");
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("给你一份数据");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
这是DemoServlet02
已经部署成功
<servlet>
<servlet-name>DemoServlet02</servlet-name>
<servlet-class>com.xhxy.Servlet.DemoServlet02</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DemoServlet02</servlet-name>
<url-pattern>/DemoServlet02</url-pattern>
</servlet-mapping>
启动服务后点击按钮无法获取到数据,我认为是load方法中的url路径没有写对,导致没有访问到DemoServlet02
这是项目的目录
求助各位 我这个load(url)要怎么写?