js前台到后台加载经典

来源:互联网 发布:看美剧学英语软件 编辑:程序博客网 时间:2024/06/08 02:09
 <script type="text/javascript">
         $(function($) {
                
                    var url = “http://localhost:8080/asdsad”;
                    $.post(url, function(data){
                        if(data.code == 200){
                            var html = '';
                            html = fun(data.data, html);
                        }
                    })
                });
            function  fun(videos, html){
                var val = '<td><div id="flashContent"></div></td>';
                for (var i = 0; i <videos.length; i++) {
                    var id = "asd"+i
                    var video = videos[i];
                    if (i%3==0) {
                        $("#video table").children(":last").append("<tr></tr>");
                    }
                             $("#video table").children(":last").append("<a onclick='playVideo("+i+")' >"+"<div id="+id+">"+"</div>"+videoinfo.type+i+"</a>");
                    //这是播放器
                    var swfVersionStr = "11.1.0";
                    var xiSwfUrlStr = "assets/playerProductInstall.swf";
                    var flashvars = {};
                    var params = {};
                    params.quality = "high";
                    params.bgcolor = "#FFFFFF";
                    params.allowscriptaccess = "sameDomain";
                    params.allowfullscreen = "true";
                    var attributes = {};
                    attributes.id = "fmsclient"+i;
                    attributes.name = "fmsclient"+i;
                    attributes.align = "middle";
                    swfobject.embedSWF(
                        "fmsclient.swf", "flashContent"+i,
                        "364px", "228px",
                        swfVersionStr, xiSwfUrlStr,
                        flashvars, params, attributes);
                    // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
                    swfobject.createCSS("#flashContent"+i, "display:block;text-align:left;");

                };

        }       </script>


后台接收:

@Controller
@RequestMapping("/qwe/reqw")
public class aController extends BaseController {
    @Autowired
    private aService aService;
    
//    /qw/qw/redw/qw.json
    @ResponseBody
    @RequestMapping("/getVideo.json")
    public void getVideo(HttpServletRequest request){
        System.out.println("连通");
        String url ="http://localhost:8080/ss/myresource?"+"&name="+name;
        
        ConnectServer(url);
    }
    
    
    @ResponseBody
    @RequestMapping("/geta.json")
    public HashMap<String, Object> geta(HttpServletRequest request,MpTerminalCondition mpTerminal){
        HashMap<String, Object> result = new HashMap<String, Object>();
    
        List<aCondition> terminals = aService
                .selectSelective(aTerminal);
        result.put("code", 200);
        result.put("data", terminals);
        return result;
    }
    
    
    //请求连接到服务器的连接:
    
    public void ConnectServer(String url){
                PrintWriter out = null;
                BufferedReader in = null;
                String result = "";
                try {
                    URL realUrl = new URL(url);
                    // 打开和URL之间的连接
                    URLConnection conn = realUrl.openConnection();
                    // 设置通用的请求属性
                    conn.setRequestProperty("accept", "*/*");
                    conn.setRequestProperty("connection", "Keep-Alive");
                    conn.setRequestProperty("user-agent",
                            "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
                    // 发送POST请求必须设置如下两行
                    conn.setDoOutput(true);
                    conn.setDoInput(true);
                    // 获取URLConnection对象对应的输出流
                    out = new PrintWriter(conn.getOutputStream());
                    // 发送请求参数
                  
                    // flush输出流的缓冲
                    out.flush();
                    // 定义BufferedReader输入流来读取URL的响应
                    in = new BufferedReader(
                            new InputStreamReader(conn.getInputStream()));
                    String line;
                    while ((line = in.readLine()) != null) {
                        result += line;
                    }
                } catch (Exception e) {
                    System.out.println("发送 POST 请求出现异常!" + e);
                    e.printStackTrace();
                }
                // 使用finally块来关闭输出流、输入流
                finally {
                    try {
                        if (out != null) {
                            out.close();
                        }
                        if (in != null) {
                            in.close();
                        }
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }






function playVideo(i){
   
    var url = '/a/a/a/getVideo.json';
    console.log(videosPublic);
    var params = videosPublic[i];
$.post(url, params,function(data){
if(data.code == 200){
location.href = '/';
}
});//params.rtmpAddress   "hello"   params.rtmpAddress,params.rtmpParams
var  x= document.getElementById("fmsclient"+i).displayVideoPanel(params.rtmpAddress,params.rtmpParams); 
    }



》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

要传到restful服务端的话,必须这样:

请求端是这样的:

String name="zhangsan";
ConnectRed5Server("http://localhost:8080/a/a?name="+name);

restful接受端是这样:

@Path("a")
public class a{


    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public void getIt2(@Context UriInfo info) {
  MultivaluedMap<String,String> queryParameters = info.getQueryParameters();
    List<String> list1 = queryParameters.get("name");
    MultivaluedMap<String,String> queryParameters = info.getQueryParameters();
    List<String> list1 = queryParameters.get("name");
    }




0 0
原创粉丝点击