Ajax实现局部刷新的要领实例(2)

package test3_2.ajax; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/ajaxServlet") public class AjaxServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); //1、获取ajax通报过来的参数信息 String flag = request.getParameter("flag"); System.out.println(flag); //2、需要返回的数据信息 String data = " "; if("one".equals(flag)){//风行歌曲 data = "张三"; }else if("two".equals(flag)){//经典歌曲 data = "李四"; }else if("three".equals(flag)){//摇滚歌曲 data = "老王"; } //3、将数据信息回写给ajax response.getWriter().write(data); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }

截图:

Ajax实现局部刷新的方式实例

Ajax实现局部刷新的方式实例

Ajax实现局部刷新的方式实例

总结

到此这篇关于Ajax实现局部刷新的文章就先容到这了,更多相关Ajax局部刷新内容请搜索剧本之家以前的文章或继承欣赏下面的相关文章但愿各人今后多多支持剧本之家!

您大概感乐趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsdfgg.html