热搜:NVER node 开发 php

AjaxAnyWhere 实现页面局部刷新_html/css_WEB-ITnose

2024-11-20 17:45:01
AjaxAnyWhere 实现页面局部刷新_html/css_WEB-ITnose

这个比较jquery、单纯ajax异步简单多了,不多说了直接上代码。


需要引入:ajaxanywhere-1.2.1.jar (最新)和 /ajaxAnyWhereDemo/WebRoot/js/aa.js  ,免费下载地址http://download.csdn.net/detail/xuke6677/8064977

目录结构如下:




1、ListBean.java 实体类   

package org.ydd.test;public class ListBean {	private String id;	private String name;	private String sex;	private String work;	private String address;        //get(),set()…… 省略}


2、   AjaxAnyWhereTest.java  后台servlet


package org.ydd.test;import java.io.IOException;import java.util.ArrayList;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class AjaxAnyWhereTest extends HttpServlet {	private static final long serialVersionUID = -5750167075517567170L;	List rs = new ArrayList();		@Override	public void init() throws ServletException {		ListBean userBean = new ListBean();		userBean.setId("1");		userBean.setName("张三");		userBean.setSex("123");		userBean.setWork("prom");		userBean.setAddress("fdsfsd");		rs.add(userBean);	}	public void doGet(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {			doPost(request, response);	}	public void doPost(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		ListBean userBean = new ListBean();		String id= request.getParameter("id");		if(!"".equals(id) && id!=null){			userBean.setId(id);			userBean.setName(request.getParameter("name"));			userBean.setAddress(request.getParameter("address"));			userBean.setSex(request.getParameter("sex"));			userBean.setWork(request.getParameter("work"));			rs.add(userBean);		}				if(rs.size()>0){			request.setAttribute("queryList", rs);		}				request.getRequestDispatcher("list.jsp").forward(request, response);	}}

3、web.xml

<?xml version="1.0" encoding="UTF-8"?>AjaxAnywhereorg.ajaxanywhere.AAFilterencodingGB2312ajaxencodingGB2312AjaxAnywhere*AjaxAnyWhereTestorg.ydd.test.AjaxAnyWhereTestAjaxAnyWhereTest/AjaxAnyWhereTestindex.jsp

4、index.jsp

      My JSP 'index.jsp' starting page







5、list.jsp


注:需要引入


      ajaxAnywhere局部刷新





列表
ID编号   姓名 性别 工作行业 地址
${listbean.id} ${listbean.name} ${listbean.sex} ${listbean.work} ${listbean.address}



录入

ID编号 :
姓名 :
性别 :
工作行业:
地址: