i have been given an assignment to right a web client in java language please can i get help with the codes to implement that?.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i have been given an assignment to right a web client in java language please can i get help with the codes to implement that?.
Hello 5723,
Have you started this assignment yet? We will need more details to be able to help you move forward.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
The code i have is this and i was asked to write it into a .html file
package httpconn; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.*; import java.net.URL; import java.net.URLConnection; /** * * @author HARLEY */ //URLExp public class Main { public static void main(String[] args) { try { URL google = new URL("http://www.google.com/"); URLConnection yc = google.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc .getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); //File tst = new File("tst.html"); //FileOutputStream out = new FileOutputStream(tst); } in.close(); } catch (Exception e) { e.printStackTrace(); } } }
Last edited by JavaPF; June 10th, 2009 at 10:58 AM. Reason: Please use [code] [/code] tags! Read my sig.
Hello 5723,
Try this:
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.*; import java.net.URL; import java.net.URLConnection; /** * * @author HARLEY * JavaProgrammingForums.com */ public class Main { public static void main(String[] args) { String newLine = System.getProperty("line.separator"); try { Writer output = null; File file = new File("index.html"); output = new BufferedWriter(new FileWriter(file)); URL google = new URL("http://www.google.com/"); URLConnection yc = google.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { //System.out.println(inputLine); output.write(inputLine); output.write(newLine); } in.close(); output.close(); System.out.println("File written"); } catch (Exception e) { e.printStackTrace(); } } }
The source from the webpage will be saved to index.html in the application root directory.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
i get an error code like this in my netbeans development area
java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:154) at java.net.Socket.connect(Socket.java:568) at java.net.Socket.connect(Socket.java:518) at sun.net.NetworkClient.doConnect(NetworkClient.java:174) at sun.net.www.http.HttpClient.openServer(HttpClient.java:404) at sun.net.www.http.HttpClient.openServer(HttpClient.java:516) at sun.net.www.http.HttpClient.<init>(HttpClient.java:240) at sun.net.www.http.HttpClient.New(HttpClient.java:321) at sun.net.www.http.HttpClient.New(HttpClient.java:333) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:806) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:747) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:672) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1020) at httpfile.main(httpfile.java:26)
thanks my problem has been solved
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
please tell me what is a servelet and how is it created
What Is a Servlet?
A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers. For such applications, Java Servlet technology defines HTTP-specific servlet classes.
What Is a Servlet? - The Java EE 5 Tutorial
Java Servlet tutorials,JSP tutorial,Servlet Example,Servlet tutorial,J2EE tutorials
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.