kjhkjh <%@ page import="java.net.URLEncoder,java.util.Enumeration,java.util.HashMap, java.net.HttpURLConnection,java.net.URL,java.io.BufferedReader,java.io.InputStreamReader" %><% // Smaato Code Snippet JSP // Copyright Smaato, Inc., All rights reserved // Rev: 20131107 // Version: 1.2 String jspsnip= "102"; // Your publisher-id String somaPub ="1100034656"; // The adspace-id String somaAdspace ="130289507"; // The user-id, the soma-server has generated at first request // Attention: // If it is possible to track each single user on your side, the user-parameter should be empty (&user=). // Inside the response, there will be the "SomaUserID"-header, with a new generated user-id. // This new generated "SomaUserID" should be used as "&user="-parameter // for every following request of this particular user. // // If it is not possible on your side, to split apart different users // (and re-recognize him afterwards at each request) // please use the following ID for ALL users/requests // ExampleValue: 900 String somaUserID = "900"; // max. width of the wished ad (e.g. MMA small is 120) String somaWidth = ""; // max. height of the wished ad (e.g. MMA small is 20) String somaHeight = ""; // Position of the ad String somaPos = "top"; // Amount of ads which should be requested. Default is "1" int somaAdCount = 1; // The wished format of the requested ad. Default: ALL (other possible values: "IMG" or "TXT") String somaAdFormat = "ALL"; boolean beacon= true; ///////////////////////////////// // Do not edit below this line // ///////////////////////////////// // This section defines Smaato functions and should be used AS IS. String somaResponseFormat = "HTML"; // Check, which url to use (test or live) String somaUrl = "http://soma.smaato.com/oapi/"; // Timeout for the request in millseconds int somaTimeout = 4000; // The user-agent of the client device String somaUa = request.getHeader("User-Agent"); if (request.getHeader("X-OperaMini-Phone-UA") != null) { somaUa = request.getHeader("X-OperaMini-Phone-UA"); } else if (request.getHeader("X-Original-User-Agent") != null) { somaUa = request.getHeader("X-Original-User-Agent"); } else if (request.getHeader("X-Device-User-Agent") != null) { somaUa = request.getHeader("X-Device-User-Agent"); } // The user-agent of the client device as encoded device-parameter somaUa = URLEncoder.encode(somaUa, "UTF-8"); // Headers to use for the request HashMap somaHeaders = new HashMap(); // IP of the client String somaIp = request.getRemoteAddr(); // Other client header informations, which are set using the prefix "X-MH-" Enumeration somaEH = request.getHeaderNames(); while (somaEH.hasMoreElements()) { String name = (String) somaEH.nextElement(); String val = request.getHeader(name); somaHeaders.put("X-MH-" + name, val); } // URL including parameter somaUrl = somaUrl + "reqAd.jsp?pub=" + somaPub + "&adspace=" + somaAdspace + "&adcount=" + somaAdCount + "&response=" + somaResponseFormat + "&devip=" + somaIp + "&user=" + somaUserID + "&format=" + somaAdFormat + "&position=" + somaPos + "&height=" + somaHeight + "&width=" + somaWidth + "&device=" + somaUa+"&beacon="+beacon+ "&jspsnip="+ jspsnip; StringBuffer somaOutput = new StringBuffer(); // Open the URL connection HttpURLConnection c = null; try { URL url = new URL(somaUrl); c = (HttpURLConnection) url.openConnection(); c.setRequestMethod("GET"); c.setConnectTimeout(somaTimeout); c.setReadTimeout(somaTimeout); for (String key : somaHeaders.keySet()) { c.setRequestProperty(key, somaHeaders.get(key)); } BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { somaOutput.append(inputLine); } in.close(); // Write the response into the page out.print(somaOutput.toString()); } catch (Exception e) { // Exception-Handling } finally { if (c != null) { c.disconnect(); } } %>

Comentários