Output streaming of a servlet

A

anu

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+"&param2="+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&param2=anu
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://localhost:8080/Scroll_Sample/ScrollServlet?param1=anu&param2=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.....
 
C

ck

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+"&param2="+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&param2=anu
java.io.IOException: Server returned HTTP response code: 500 for URL:http://localhost:8080/Scroll_Sample/ScrollServlet?param1=anu&param2=anu
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection....
1149)
at ServletConnect.main(ServletConnect.java:61)
can anyone suggest any idea pls?
Thanks in Advance.....


What happens when you simply paste
http://localhost:8080/Scroll_Sample/ScrollServlet?param1=anu&param2=anu
in browser?

Instead of using URL object, in my opinion Commons HTTP client would
be a better option.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

anu said:
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+"&param2="+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&param2=anu
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://localhost:8080/Scroll_Sample/ScrollServlet?param1=anu&param2=anu
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:
1149)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top