JSP页面点击“上移下移”链接排序
来源:互联网 发布:2015年进出口贸易数据 编辑:程序博客网 时间:2024/06/05 16:51
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="hoo" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>排序</title></head><body><form action="" method=post><table border=1><hoo:forEach items="${requestScope.al }" var="user"><tr><td>${user.id }</td><td>${user.name }</td><td><a href=SortServlet?type=up&id=${user.id }>上移</a></td><td><a href=SortServlet?type=down&id=${user.id }>下移</a></td></tr></hoo:forEach></table></form></body></html>IndexServlet.java
package com.controller;import java.io.IOException;import java.util.ArrayList;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 com.domain.User;import com.service.HuService;@WebServlet("/IndexServlet")public class IndexServlet extends HttpServlet {protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubthis.doPost(request, response);}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubHuService hs=new HuService();request.getSession().setAttribute("hs", hs);ArrayList<User> al=(ArrayList<User>) hs.getList();request.setAttribute("al", al);request.getRequestDispatcher("index.jsp").forward(request, response);}}
SortServlet.java
package com.controller;import java.io.IOException;import java.util.ArrayList;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 com.domain.User;import com.service.HuService;@WebServlet("/SortServlet")public class SortServlet extends HttpServlet {private static final long serialVersionUID = 1L; public SortServlet() { super(); // TODO Auto-generated constructor stub }protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubthis.doPost(request, response);}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String type=request.getParameter("type");String id=request.getParameter("id");HuService hs=(HuService) request.getSession().getAttribute("hs");hs.sort(type, id);ArrayList<User> al=(ArrayList<User>) hs.getList();request.setAttribute("al", al);request.getRequestDispatcher("index.jsp").forward(request, response);}}
HuService.java
package com.service;import java.util.*;import com.domain.User;public class HuService {private ArrayList<User> list;public HuService(){list=new ArrayList<>();list.add(new User("1","疯狂JAVA"));list.add(new User("2","百度"));list.add(new User("3","谷歌"));list.add(new User("4","腾讯"));list.add(new User("5","新浪"));list.add(new User("6","网易"));list.add(new User("7","搜狐"));}public List<User> getList(){return list;}public void sort(String type,String id){if(type.equals("up")){for(int i=0;i<list.size();i++){User user=list.get(i);if(user.getId().equals(id)){if((i-1)>=0){User u=list.get(i-1);System.out.println(u.getName());user.setId(u.getId());u.setId(id);}break;}}}else if(type.equals("down")){for(int i=0;i<list.size();i++){User user=list.get(i);if(user.getId().equals(id)){if((i+1)<=(list.size()-1)){User u=list.get(i+1);user.setId(u.getId());u.setId(id);}break;}}}Collections.sort(this.getList(), new HuComparator());}}class HuComparator implements Comparator<User>{@Overridepublic int compare(User o1, User o2) {int result = o1.getId().compareTo(o2.getId());return result;}}
- JSP页面点击“上移下移”链接排序
- jsp页面的上移下移(可以勾选勾选多个)
- mssql 实现排序上移下移
- DataTables上移下移排序、拖拽排序
- 通用的排序的上移下移功能
- JS移动li行数据,点击上移下移
- Jquery Datetable 行上移、下移 点击 和 删除事件
- 早起的鸟儿有虫吃---页面模块上移下移
- 对LinkedHashMap进行数据项的上移或下移排序
- 表格操作类(添加,删除,排序,上移,下移)
- 表格操作类(添加,删除,排序,上移,下移)
- 表格操作类(添加,删除,排序,上移,下移)
- JQUERY JS实现select上移下移自定义排序
- 表格操作类(添加,删除,排序,上移,下移)
- jquery 动态控制表格,添加,删除,上移,下移,排序
- listBox 上移下移
- div 上移下移技术
- table : 上移,下移,置顶
- Java核心技术,支撑Java程序对外接口的I/O
- LeetCode | Validate Binary Search Tree
- Shiro和AJAX完美整合
- How to think like a Computer Scientist: 课后习题第十八章3
- 网页艺术设计基础
- JSP页面点击“上移下移”链接排序
- cannot be hot swapped into a running virtal machine的解决方法
- 10. 翻转句子中单词的顺序。
- POJ 3007 Organize Your Train part II
- 实模式和保护模式
- 123我们456
- 大数据量生成脚本及导入策略
- awk脚本学习小结
- 阿里2014届校园招聘面经