1.jsp页面,记得引入json包
- <%@ page language="java" contentType="text/html; charset=utf-8"
- pageEncoding="utf-8"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <script type="text/javascript" src="js/jquery-2.1.3.js"></script>
- <script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
- <meta http-equiv="Content-Type" content="text/html; charset=utf8">
- <title>Insert title here</title>
- <script type="text/javascript">
- function ajaxTest(){
- var array = $('#dg').datagrid("getSelections");
if(array.length>0){
//定义数组,通过下边的用来存储选中记录的Id
var ids = new Array();
for (i = 0; i < array.length; i++) {
ids[i] = array[i].supId;
//alert(ids[i]);
} - $.ajax({
- //向后台传送删除的那条数据的id
- data:{supId:ids}
- type:"GET",
- dataType: 'json',
- url:"user/login.action",
- error:function(data){
- alert(data);
- },
- success:function(data){
- alert(data);
- 页面回显
- $("#result").html(data) ;
- }
- });
- }
- </script>
- </head>
- <body>
- <input type="text" name="name" id="name"/>
- <input type="submit" value="" οnclick="ajaxTest();"/>
- <div id="result"></div>
- </body>
- </html>
- 2.后台页面
- package com.gxa.bj.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.gxa.bj.model.Account;
import com.gxa.bj.model.Page;
import com.gxa.bj.model.SupplierInfo;
import com.gxa.bj.service.SupplierInfoService;
import com.gxa.bj.util.JSONHelper;
@Controller
public class SupplierInfoAction {
private SupplierInfoService supplierInfoService;
public SupplierInfoService getSupplierInfoService() {
return supplierInfoService;
}
public void setSupplierInfoService(SupplierInfoService supplierInfoService) {
this.supplierInfoService = supplierInfoService;
}
@RequestMapping(value="/delete.action")
public void delete(String supId,HttpServletRequest request,HttpServletResponse resp){
resp.setCharacterEncoding("utf-8");
PrintWriter pw=null;
try {
pw = resp.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(supplierInfoService.removeItem(supId)>0){
pw.write("删除成功");
}else{
pw.write("失败失败");
}
}
public void delete(String supId,HttpServletRequest request,HttpServletResponse resp){
resp.setCharacterEncoding("utf-8");
PrintWriter pw=null;
try {
pw = resp.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(supplierInfoService.removeItem(supId)>0){
pw.write("删除成功");
}else{
pw.write("失败失败");
}
}
- }