Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 238 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.8K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 437 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Download URL content using jsp

Hi Every one,
i need to call one web service which downloads a PDF document, i am trying with jsp but final output is corrupted meaning unreadable format with question marks like ..
sb String - %PDF-1.4 %���� 2 0 obj <> stream ���� JFIF ����C $ #," '.0,)7( 44418=9'.<2432��C 2! !22222222222222222222222222222222222222222222222222�� � � �� ��� } !1A Qa "q 2��� #B�� R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ��� w !1 AQ aq "2� B���� #3R� br� $4�%� &'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������� ��� ?��(� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (� � (��&% ( Ҁ`:P � ��� �� �@ ( � �� ��� �@ � Nh ��i� � �� � q qh�. �#� �, [email protected]�[email protected]� [email protected] �P �* �[email protected] � � � P m `�.!
Below is my code which i am trying
<%@ page import = "java.io.BufferedReader" %><%@ page import = "java.io.IOException;" %><%@ page import = "java.io.InputStreamReader" %><%@ page import = "java.io.OutputStream" %><%@ page import = "java.io.*" %><%@ page import = "java.net.HttpURLConnection" %><%@ page import = "java.net.MalformedURLException" %><%@ page import = "java.net.URL" %><%@ page import = "com.sun.org.apache.xerces.internal.impl.dv.util.Base64" %><html> <body> <center> <table width = "100%" border = "1" align = "center"> <% String USER_AGENT = "Mozilla/5.0"; String targeturl = "http://XXX";\\Commented out my url String uniqueId = "12345678_236683804-121"; String doc_type="litpack"; String rtv_app="Portal"; URL myurl = new URL(targeturl + "?" + "unique_id=" + uniqueId + "&doc_type=" + doc_type + "&rtv_app=" + rtv_app); HttpURLConnection con = (HttpURLConnection)myurl.openConnection(); con.setDoOutput(true); con.setDoInput(true); con.setRequestProperty("Accept", "application/pdf"); con.setRequestProperty("Method", "GET"); String username = "admin"; String password = "password"; String userpassword = username + ":" + password; String encodedAuthorization = Base64.encode(userpassword.getBytes()); con.setRequestProperty("Authorization", "Basic "+encodedAuthorization); OutputStream os = con.getOutputStream(); StringBuilder sb = new StringBuilder(); int HttpResult =con.getResponseCode(); if(HttpResult ==HttpURLConnection.HTTP_OK) { BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8")); String line = null; while ((line = br.readLine()) != null) { sb.append(line + "\n"); } br.close(); out.println("sb String - "+sb.toString()); }else{ out.println(con.getResponseCode()); out.println(con.getResponseMessage()); } String text = sb.toString(); %> </table> </center> </body></html>
Answers
-
Please reply issue is not solve yet...
Thanks