| | |
help me to read a file from another machine in the network.
![]() |
Now to connect via a Proxy **I think** you need to use the following method while opening the URL Connection using this "openConnection()" method of the URL class.
It takes an object of the Proxy class as an argument.
To construct the Proxy using the Proxy(Proxy(ProxyType, SocketAddress)) constructor itself you will need two items, First is the Proxy type, I am guessing yours is an HTTP proxy server so use Proxy.Type.HTTP as the first argument.
Next you will need a SocketAddress, the SocketAddress class is itself abstract so you will need to use the InetSocketAddress class which is its concrete sub class. Using InetSocketAddress(String hostname, int port) create an object of the InetSocketAddress of your Proxy Server (using the host name and port on which your proxy is running).
So that **should** do the job of getting past your Proxy.
It takes an object of the Proxy class as an argument.
To construct the Proxy using the Proxy(Proxy(ProxyType, SocketAddress)) constructor itself you will need two items, First is the Proxy type, I am guessing yours is an HTTP proxy server so use Proxy.Type.HTTP as the first argument.
Next you will need a SocketAddress, the SocketAddress class is itself abstract so you will need to use the InetSocketAddress class which is its concrete sub class. Using InetSocketAddress(String hostname, int port) create an object of the InetSocketAddress of your Proxy Server (using the host name and port on which your proxy is running).
So that **should** do the job of getting past your Proxy.
Last edited by stephen84s; Dec 16th, 2008 at 7:33 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
•
•
Join Date: Jan 2008
Posts: 71
Reputation:
Solved Threads: 1
Using this code the file can be uploaded to the server
Java Syntax (Toggle Plain Text)
<%@ page import="java.io.*" %> <% String contentType = request.getContentType(); System.out.println("Content type is :: " +contentType); if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) { DataInputStream in = new DataInputStream(request.getInputStream()); int formDataLength = request.getContentLength(); byte dataBytes[] = new byte[formDataLength]; int byteRead = 0; int totalBytesRead = 0; while (totalBytesRead < formDataLength) { byteRead = in.read(dataBytes, totalBytesRead, formDataLength); totalBytesRead += byteRead; } String file = new String(dataBytes); String saveFile = file.substring(file.indexOf("filename=\"") + 10); //out.print("FileName:" + saveFile.toString()); saveFile = saveFile.substring(0, saveFile.indexOf("\n")); //out.print("FileName:" + saveFile.toString()); saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\"")); //out.print("FileName:" + saveFile.toString()); //out.print(dataBytes); int lastIndex = contentType.lastIndexOf("="); String boundary = contentType.substring(lastIndex + 1,contentType.length()); //out.println(boundary); int pos; pos = file.indexOf("filename=\""); pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; int boundaryLocation = file.indexOf(boundary, pos) - 4; int startPos = ((file.substring(0, pos)).getBytes()).length; int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length; out.println(boundaryLocation+"pppp"+file.length()+"ooooooooooooo"+(endPos-startPos)+"kkkkk"); saveFile = "/usr/programs/apache-tomcat-6.0.16/webapps/Pinnacle/hr_photoGallery/" + saveFile; FileOutputStream fileOut = new FileOutputStream(saveFile); //fileOut.write(dataBytes); fileOut.write(dataBytes, startPos, file.length()); fileOut.flush(); fileOut.close(); out.println("File saved as " +saveFile); } %>
![]() |
Other Threads in the Java Forum
- Previous Thread: a beginner in java needs help
- Next Thread: Intranet aplication
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows







:-)