Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Output streaming of a  servlet

Thread view: 
anu - 14 Mar 2007 08:11 GMT
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.....
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&param2=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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.