| Author |
Invoking a servlet from an application??
|
Sajee Joseph
Ranch Hand
Joined: Jan 17, 2001
Posts: 200
|
|
Hello, I am invoking a servlet from an application. But it doesnt seem to work. It doesnt give an exception either. Here is teh code i used mport java.net.URL; import java.net.URLConnection; import java.io.*; class HTTPS1 { public static void main(String args[]) { HTTPS1 url = new HTTPS1(); url.connectToUrl(); } public void connectToUrl() { try { URL url = new URL("http://mildh0679:7070/gem/servlet/gem.BatchReportServlet?ACTION=BATCH"); System.out.println("Trying to connect to URL - " + url); URLConnection con = url.openConnection(); System.out.println("con - " + con); con.setDoOutput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/x-java-serialized-object"); OutputStream os = con.getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(os); ObjectOutputStream oos = new ObjectOutputStream(bos); System.out.println("writing hello"); oos.writeObject("hello"); oos.flush(); oos.close(); System.out.println("closed"); } catch(Exception e) { e.printStackTrace(); } } } Any clues on this?
|
 |
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
|
|
How does it not work? Is the servlet executed in the container? Does it receive the string? Can you try reading the output from the servlet? What exactly is the output of the servlet? More details will make it easier for us.
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
I suspect the task might become easier by using Jakarta HttpClient: http://jakarta.apache.org/commons/httpclient/ Moving to Sockets and Internet Protocols...
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
akalanka de silva
Greenhorn
Joined: Sep 14, 2004
Posts: 18
|
|
|
hey iam not a servlet expert and i want to learn it.by the way i make a chat programme by applet.and i also want to invoke the servlet.but i dont know how do it.but i understand u r program and i want to know what method is invoke in the servlet
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8264
|
|
|
Since our friend invokes con.setDoOutput(true), the request will be an HTTP POST and it will invoke doPost() on our servlet. Please do not follow his example, as it will not work. He is creating a request but never sending it to the remote server. One must either invoke connect() or invoke a method which depends on connect(), like getInputStream(), or the request is never made. For the correct use of URLConnection, look at the Java Documentation and thisJava Almanac example
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
 |
|
|
subject: Invoking a servlet from an application??
|
|
|