列表页:selectaddress.jsp
js页:ajax_edit.js
jsp处理页:editaddress.jsp
上传工具类:UploadUtil.java
思想:由于安全问题,javascript操纵不了文件, 导致ajax不能动态上传文件,所以选择了iframe,
列表页把form表单提交到一个隐式的iframe里面,设置表单的属性
复制代码 代码如下:
enctype='multipart/form-data' target='hidden_frame'
然后,处理页处理后返回
复制代码 代码如下:
out.println('<script>parent.callback(" 返回值 ")</script>');
列表页执行回调函数!
selectaddress.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="com.wap3.navigater.service.*" %> <%@ page import="com.wap3.navigater.dao.*" %> <%@ page import="com.wap3.navigater.pojo.*" %> <%@ page import="com.wap3.navigater.util.*" %> <%@ page import="java.util.*" %> <%@ page import="java.text.*" %> <!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"> <script type="text/javascript" src="https://www.jb51.net/js/jquery.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/ajax_edit.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/jquery.jclock.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/common.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/jquery.form.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/fileTypeJudge.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/jquery.datepick.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/jquery.datepick-zh-CN.js"></script> <link media=all href="https://www.jb51.net/css/common.css" type=text/css rel=stylesheet> <title>Insert title here</title> <style type="text/css"> @import "inc/jquery.datepick.css"; </style> <script type="text/javascript"> var $imgthis; $(function(){ var oldValue; $(".package_list .edit").bind("dblclick",function(){ oldValue = $(this).text(); $(this).ajax_edit("editaddress.jsp",oldValue); }); $(".package_list .edit_img").bind("dblclick",function(){ // oldValue = $(this).html(); $imgthis = $(this); $(this).parents("tr.package_list").siblings(".package_list").find(":input.cancel").trigger("click"); $(this).ajax_edit_img("editaddress.jsp",oldValue); }); $(".package_list .edit :input[type!=file]:visible").live("blur",function(){ $(this).ajax_handle("editaddress.jsp?action=edit",oldValue); }); $("#editcategoryName").live("change",function(){ $(this).ajax_handle("editaddress.jsp?action=edit",oldValue); }); $("#del").click( function () { if($(":checkbox.urlid:checked").size()>0){ var result = confirm("不可恢复的操作:确定要吗?"+ '\n' +"提示:如果删除大类会删除大类及下面的子类!!!"); if (result) { var url = location.href; alert(url); return ; $(".main_table").wrap("<form action='selectaddress.jsp?action=del' method='post'></form>"); $("#selectAddressForm").submit(); } }else{ alert("请选择要删除的项目!"); return false; } }); }); function callback(msg) //处理JSP回调 过来的参数 { $imgthis.html("<img src='"https://www.jb51.net/article/+msg+"' title='"https://www.jb51.net/article/+msg+"' />"); } </script> </head> <body> <% String action = ParameterUtil.getStringParameter(request,"action",""); FriendurlDao friendurlDao = new IbatisFriendurlDao(); if("del".equals(action)){ int[] urlids = ParameterUtil.getIntArrayParams(request,"urlid"); for(int urlid : urlids){ friendurlDao.deleteFriendurlByP(urlid); } } String navigaterPage = request.getRequestURL().toString(); if(request.getQueryString()!= null){ navigaterPage += "?"+request.getQueryString(); } int categoryId = ParameterUtil.getIntParameter(request,"categoryId",0); if(categoryId == 0){ response.sendRedirect("selectcategory.jsp"); return; } int pageSize = ParameterUtil.getIntParameter(request,"pageSize",10); int pageNo = ParameterUtil.getIntParameter(request,"pageNo",1); String orderBy = ParameterUtil.getStringParameter(request,"orderBy","sequence"); int ascOrDesc = ParameterUtil.getIntParameter(request,"ascOrDesc",0); CategoryDao categoryDao = new IbatisCategoryDao(); Category category = categoryDao.selectCategoryByP(categoryId); String categoryName = category.getCategoryName(); Friendurl friendurl = new Friendurl(); friendurl.setCategoryId(categoryId); friendurl.addOrderBy(orderBy,ascOrDesc); List<Friendurl> friendurlList = friendurlDao.selectFriendurlByE(friendurl); //分页 int totallpage = (int) Math.ceil(((double) friendurlList .size() * 1.0D)/ (double) pageSize); pageNo =pageNo <= 0 ? 1 : pageNo; pageNo =pageNo > totallpage ? totallpage : pageNo; DataPageUtil datePage = new DataPageUtil(friendurlList ,friendurlList .size(),pageSize, pageNo); boolean hasPrerPage = datePage.hasPrevPage(); boolean hasNextPage= datePage.hasNextPage(); int curpageNo = datePage.getPageNo(); int pageCount = datePage.getPageCount(); friendurlList = DataPageUtil.subList(friendurlList, pageSize, pageNo); if(friendurlList == null && friendurlList.size()<=0) { out.println("没有您需要的数据"); }else{ %> <%@include file="inc/header.jsp" %> <div id = "mainbox"> <div class = "c1"> <table cellspacing="0" cellpadding="0"> <tr> <th colspan="13" bgcolor="#006699">条目列表</th> </tr> <tr> <td bgcolor="#009999"> <input type="checkbox"><label for="AllORNoall">全选</label> <input type="button" value="反选" /> </td> <td bgcolor="#009999">站点名称</td> <td bgcolor="#009999">站点别名</td> <td bgcolor="#009999">归类</td> <td bgcolor="#009999">公司地址</td> <td bgcolor="#009999">文字链接</td> <td bgcolor="#009999">图片链接</td> <td bgcolor="#009999">描述</td> <td bgcolor="#009999">有效开始时间</td> <td bgcolor="#009999">有效结束时间</td> <td bgcolor="#009999">电话</td> <td bgcolor="#009999">位置排序</td> <td bgcolor="#009999">推荐序号</td> </tr> <% for(Friendurl friendurlTemp:friendurlList) { int urlId = friendurlTemp.getUrlid(); String siteName = friendurlTemp.getSitename(); String alias = friendurlTemp.getAlias(); String address = friendurlTemp.getAddress(); String texturl = friendurlTemp.getTexturl(); String imageurl = friendurlTemp.getImageurl(); String description = friendurlTemp.getDescription(); Date validbegintime = friendurlTemp.getValidbegintime(); Date validendtime = friendurlTemp.getValidendtime(); String mobile = friendurlTemp.getMobile(); int sequence = friendurlTemp.getSequence(); int filter = friendurlTemp.getFilter(); %> <tr> <td><input type="checkbox" value=<%= urlId%> /></td> <td><%=siteName %></td> <td><%=alias %></td> <td><%=categoryName%></td> <td><%=address %></td> <td><%=texturl%></td> <td><img src='https://www.jb51.net/<%=imageurl%>' title='https://www.jb51.net/<%=imageurl%>'/></td> <td><%=description%></td> <td><%=validbegintime == null || "".equals(validbegintime)? "--:--" : TimeUtil.date2Str(validbegintime)%></td> <td><%=validendtime == null || "".equals(validendtime)? "--:--" : TimeUtil.date2Str(validendtime)%></td> <td><%=mobile%></td> <td><%=sequence%></td> <td><%=filter%></td> </tr> <% } %> <tr> <td><input type="button" value="删除" /></td> <td colspan = "12">提示:双击选框修改属性值</td> </tr> </table> </div> <%@ include file="inc/pagination.jsp"%> </div> <% } %> <iframe></iframe> </body> </html>
editaddress.jsp