<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="com.wap3.navigater.util.*" %> <%@ page import="com.wap3.navigater.service.*" %> <%@ page import="com.wap3.navigater.pojo.*" %> <%@ page import="com.wap3.navigater.dao.*" %> <%@ page import="java.util.*" %> <%@ page import="java.text.*" %> <% String target = ParameterUtil.getStringParameter(request,"target",""); String action = ParameterUtil.getStringParameter(request,"action",""); if(!"".equals(target) && target != null && "edit".equals(action)){ int categoryId = 0; CategoryDao categoryDao = null; int urlid=0,status=0,sequence=0,filter=0; String sitename=null,alias=null,texturl=null,imageurl=null,description=null,mobile=null; Date validbegintime=null,validendtime=null; if("imageurl".equals(target)){ System.out.println("图片上传"); UploadUtil.upload(request, response); String imageurlpath = (String) request.getAttribute("imageurlpath"); urlid = Integer.parseInt((String)request.getAttribute("urlid")); imageurl = (String)request.getAttribute("imageurlpath"); }else{ if("categoryName".equals(target)){ String categoryName = ParameterUtil.getStringParameter(request,"categoryName",""); Category category = new Category(); category.setCategoryName(categoryName); categoryDao = new IbatisCategoryDao(); Category category2 = categoryDao.selectCategoryByE(category).get(0); categoryId = category2.getCategoryId(); }else{ categoryId = ParameterUtil.getIntParameter(request,"categoryId",0); } urlid = ParameterUtil.getIntParameter(request,"urlid",0); sitename = ParameterUtil.getStringParameter(request,"sitename",""); alias = ParameterUtil.getStringParameter(request,"alias",""); texturl = ParameterUtil.getStringParameter(request,"texturl",""); imageurl = ParameterUtil.getStringParameter(request,"imageurl",""); description = ParameterUtil.getStringParameter(request,"description",""); status = ParameterUtil.getIntParameter(request,"status",0); sequence = ParameterUtil.getIntParameter(request,"sequence",0); filter = ParameterUtil.getIntParameter(request,"filter",0); mobile = ParameterUtil.getStringParameter(request,"mobile",""); validbegintime = ParameterUtil.getDateParameter(request,"validbegintime"); validendtime = ParameterUtil.getDateParameter(request,"validendtime"); } Calendar beginDay=Calendar.getInstance(); Friendurl friendurl = new Friendurl(); friendurl.setUrlid(urlid); friendurl.setSitename(sitename); friendurl.setDescription(description); friendurl.setTexturl(texturl); friendurl.setImageurl(imageurl); friendurl.setAlias(alias); friendurl.setSequence(sequence); friendurl.setMobile(mobile); friendurl.setCategoryId(categoryId); friendurl.setStatus(status); friendurl.setValidbegintime(validbegintime); friendurl.setValidendtime(validendtime); friendurl.setFilter(filter); FriendurlDao friendurlDao = new IbatisFriendurlDao(); friendurlDao.updateFriendurlByP(friendurl); Friendurl friendurl2 = friendurlDao.selectFriendurlByE(friendurl).get(0); if(friendurl2 != null){ String methodName = "get" + target.substring(0,1).toUpperCase()+target.substring(1); if(target.endsWith("time")){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); out.println(TimeUtil.date2Str(((Date)(friendurl2.getClass().getMethod(methodName,new Class[]{}).invoke(friendurl2,new Object[]{}))))); }else if("categoryName".equals(target)){ out.println(categoryDao.selectCategoryByP(friendurl2.getCategoryId()).getCategoryName()); }else if("imageurl".equals(target)){ // 无刷新关键的步骤,让iframe的父辈body执行callback这个函数 out.println("<script>parent.callback('"+friendurl2.getClass().getMethod(methodName,new Class[]{}).invoke(friendurl2,new Object[]{})+"')</script>"); }else{ out.println(friendurl2.getClass().getMethod(methodName,new Class[]{}).invoke(friendurl2,new Object[]{})); } }else{ out.println("更新失败"); } } %>
ajax_edit.js