Hi Friends, I could use your help now:-
I have to hit this Google URL and get the resultset. The result is string type. URL -> " http://www.google.com/transliterate/indic?tlqt=1&langpair=en|hi&text=amitabachan,blog&&tl_app=1 " When you put this into the URL and press enter, it will give you the modified string with the result(array). I am tring to do the same thing using Java program, but it is printing the entire HTML page of transliterate. The code is as follows:- ----------------------------------- import java.io.*; import java.net.*; import java.util.*; public class URLExample { public static void main(String[] args) throws Exception { try { Properties systemSettings = System.getProperties(); systemSettings.put("http.proxyHost", "proxy.it.iitb.ac.in"); systemSettings.put("http.proxyPort", "80"); systemSettings.put("sun.net.client.defaultConnectTimeout", "10000"); systemSettings.put("sun.net.client.defaultReadTimeout", "10000"); System.out.println("Properties Set"); Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("aaqua", "aaqua123".toCharArray()); // specify ur user name password of iitb login } }); System.setProperties(systemSettings); System.out.println("After Authentication & Properties Settings"); //the input to google api String str = " http://www.google.com/transliterate/indic?tlqt=1&langpair=en|hi&text=amitabachan,blog&&tl_app=1 "; String stringToReverse = URLEncoder.encode(str, "UTF-8"); URL url = new URL(str); URLConnection connection = url.openConnection(); connection.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter( connection.getOutputStream()); out.write("string url=" + str); out.close(); BufferedReader in = new BufferedReader( new InputStreamReader( connection.getInputStream())); String decodedString; while ((decodedString = in.readLine()) != null) { System.out.println(decodedString); } in.close(); } catch(Exception ex) { System.out.println("Exception->"+ex); ex.printStackTrace(); } } } ---------------------------------- I modified the same page as a JSP page and it opens up the transliterate page of Google. I need the result from the string entered, not the page. JSP File ------------------------------------------- <%@ page language = "java" %> <%@ page import = "java.sql.*" %> <%@ page import = "java.util.*" %> <%@ page import = "java.io.*" %> <%@ page import="java.lang.*" %> <%@ page import="java.net.*" %> <%@ page import="com.google.gwt.language.*" %> <%@ page import="com.google.gwt.user.*" %> <% try { Properties systemSettings = System.getProperties(); systemSettings.put("http.proxyHost", "proxy.it.iitb.ac.in"); systemSettings.put("http.proxyPort", "80"); systemSettings.put("sun.net.client.defaultConnectTimeout", "10000"); systemSettings.put("sun.net.client.defaultReadTimeout", "10000"); out.println("Properties Set"); Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("aaqua", "aaqua123".toCharArray()); // specify ur user name password of iitb login } }); System.setProperties(systemSettings); out.println("After Authentication & Properties Settings"); //the input to google api String str = " http://www.google.com/transliterate/indic?tlqt=1&langpair=en|hi&text=amitabachan,blog&&tl_app=1 "; String stringToReverse = URLEncoder.encode(str, "UTF-8"); URL url = new URL(str); URLConnection connection = url.openConnection(); connection.setDoOutput(true); OutputStreamWriter outwr = new OutputStreamWriter( connection.getOutputStream()); outwr.write("string url=" + str); outwr.close(); BufferedReader in = new BufferedReader( new InputStreamReader( connection.getInputStream())); String decodedString; while ((decodedString = in.readLine()) != null) { out.println(decodedString); } in.close(); } catch(Exception ex) { out.println("Exception->"+ex); PrintWriter pw = response.getWriter(); ex.printStackTrace(pw); } %> ------------------------------------------- I hope you guys can help. Regards, Jitesh Dundas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -~----------~----~----~----~------~----~------~--~---