• window.open弹出窗口调用controller


    前台图片调用js函数

    <img src='${pageContext.request.contextPath}/FlatUI/img/link.png' id='report' alt='"+data[i].report+"' onclick='changeUrl(this,"+data[i].id+")' width=15px height=15px/>
    

    js函数, 其中有一项重要处理, 在open窗口关闭的同时, 当前窗口刷新

    function changeUrl(element,id){
    				  //alert(element.alt);
    				  //window.open("/trip/changeUrl?id="+id);
    				 var winObj = window.open ("/portal/trip/changeUrl?id="+id+"&item="+element.id+"&value="+element.alt, "newwindow", "height=100, width=800, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, top=50,left=1100");
    				 var loop = setInterval(function() {       
    				        if(winObj.closed) {      
    				            clearInterval(loop);      
    				            //alert('closed');      
    				            window.location.reload();
    				        }      
    				    }, 1); 				 
    			  }
    

     controller端 /portal/trip/changeUrl

    @RequestMapping("/changeUrl")
    	public String changeUrl(Long id, String item, String value, HttpServletRequest request){
    		request.setAttribute("id",id);
    		request.setAttribute("item",item);
    		request.setAttribute("value",value);
    		//System.out.println(id);
    		return "/tripController/tripURL"; 
    	}	
    

     tripURL.jsp, 其中有个处理, 提交保存后, 关闭当前页面

    <form action="/portal/trip/updateTrip" onsubmit="window.opener=null;window.close();">
    	 	<font size="2"  color="#004779"> Change URL To:</font><br/> 
    	 	 <input type="hidden" name="id" id="id" value="${id }">
    	 	 <input type="hidden" name="item" id="item" value="${item }">
    	 	 <input type="text" name="value" id="value" value="${value }" style="color:#95a5a6; padding-left:5px;border-radius:5px;  700px; height:28px; vertical-align:middle;">
    	 	 <input type="submit"   value="Save" style="color:#2c3e50; font-size:12px;font-weight:bold; border-radius:5px; vertical-align:middle;height:30px;  60px; "/>
        </form>
    

     controller端 /portal/trip/updateTrip

    @RequestMapping("/updateTrip")
    	public String updateTrip(Long id,String item,String value,HttpServletResponse response){
    		//String result = "{"result":"success"}";
    		try {
    			URLDecoder.decode(value,"utf-8");
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		
    		
    		tripService.updateById(id,item,value);
    		
    		JSONObject data = new JSONObject();
    		try {
    			data.put("result", "success");
    		} catch (Exception e) {
    			System.out.println(e.getMessage());
    		}
    		
    		
    		PrintWriter out = null;
    		response.setCharacterEncoding("UTF-8");
    		response.setContentType("text/html; charset=UTF-8"); 
    	    try {
    	    	out=response.getWriter();
    	        out.write(data.toString());
    	        out.flush();
    			out.close();	
    			return null;
    	    } catch (IOException e) {
    	        e.printStackTrace();
    	    }	   
    		return "redirect:/trip/getAllTrip";
    	}
    
  • 相关阅读:
    Android JNI开发摘录(二)之JNI数组处理
    基于HTTP协议的下载功能实现
    javascript中的事件冒泡和事件捕获
    JavaScript模仿块级作用域
    javascript表单的Ajax 提交插件的使用
    论学历与经验
    使用Palette抽取图片颜色
    通过脚本和EL表达式获取域中数据
    需求分析
    Tomcat简介
  • 原文地址:https://www.cnblogs.com/wujixing/p/5869249.html
Copyright © 2020-2023  润新知