Hi all,
I am doing a web application.in that i have comnnected from a java
class to the servlet using URLConnection APIs.The problem now i am
facing is i need to return some values from the servlet to the calling
javaclass.how can i do this?
I have used the following code.
In the javaclass...
String location = "http://localhost:8080/Scroll_Sample/ScrollServlet?
param1="+username+"¶m2="+password;
URL testServlet = new URL(location);
URLConnection servletConnection =
testServlet.openConnection();
InputStream instr = servletConnection.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String name1 = (String)inputFromServlet.readObject();
System.out.println("name is "+name1);
System.out.println("contenttype is
"+servletConnection.getContentType());
System.out.println("within end of try");
And in the servlet............................
response.setContentType("application/x-java-serialized-object");
OutputStream outstr = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstr);
String name1="anu";
oos.writeObject(name1);
The exception i have got is
Within try
Exception isjava.io.IOException: Server returned HTTP response code:
500 for URL: http://localhost:8080/Scroll_Sample/ScrollServlet?param1=anu¶m2=anu
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://localhost:8080/Scroll_Sample/ScrollServlet?param1=anu¶m2=anu
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:
1149)
at ServletConnect.main(ServletConnect.java:61)
can anyone suggest any idea pls?
Thanks in Advance.....
ck - 14 Mar 2007 08:44 GMT
> Hi all,
> I am doing a web application.in that i have comnnected from a java
[quoted text clipped - 42 lines]
> can anyone suggest any idea pls?
> Thanks in Advance.....
What happens when you simply paste
http://localhost:8080/Scroll_Sample/ScrollServlet?param1=anu¶m2=anu
in browser?
Instead of using URL object, in my opinion Commons HTTP client would
be a better option.
--
Ck
http://www.gfour.net
Arne Vajhøj - 15 Mar 2007 00:41 GMT
> I am doing a web application.in that i have comnnected from a java
> class to the servlet using URLConnection APIs.The problem now i am
[quoted text clipped - 41 lines]
> at ServletConnect.main(ServletConnect.java:61)
> can anyone suggest any idea pls?
1) Check the log files and console window for errors that can
give a hint about why you get a code 500.
2) I am a bit skeptical about the concept of sending serialized
Java objects a body of HTTP requests. It should work, but does
seem a good choice.
Arne