4.练习开始:
(1) 【第一个例子:servlet + html + Ajax + Jquery】
首先,创建一个servlet:AjaxServlet
doGet(HttpServletRequest request, HttpServletResponse response)中写:
String param = request.getParameter("car");
System.out.println(param) ;
response.getWriter().print("{ \"name\": \"Violet\", \"occupation\": \"character\" }");
然后, 配置web.xml:
<servlet-mapping>
<servlet-name>ajaxdemo</servlet-name>
<url-pattern><strong><span style="color: rgb(51, 255, 51);">/zyxAjax/ajax.do</span></strong></url-pattern>
</servlet-mapping><welcome-file-list>
<welcome-file>ajaxW.jsp</welcome-file>
</welcome-file-list>
本文介绍了一个简单的Servlet与Ajax交互的例子。首先创建名为AjaxServlet的Servlet,并在doGet方法中获取请求参数并返回JSON格式的数据。接着配置web.xml文件以映射Servlet。

被折叠的 条评论
为什么被折叠?



