zoukankan      html  css  js  c++  java
  • 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";
    	}
    
  • 相关阅读:
    e621. Activating a Keystroke When Any Child Component Has Focus
    e587. Filling Basic Shapes
    e591. Drawing Simple Text
    e595. Drawing an Image
    e586. Drawing Simple Shapes
    e636. Listening to All Key Events Before Delivery to Focused Component
    在 PL/SQL 块的哪部分可以对初始变量赋予新值? (选择1项)
    Oracle数据库中,在SQL语句中连接字符串的方法是哪个?(选择1项)
    你判断下面语句,有什么作用?(单选)
    Oracle数据库表空间与数据文件的关系描述正确的是( )
  • 原文地址:https://www.cnblogs.com/wujixing/p/5869249.html
Copyright © 2011-2022 走看看