Solved

About InputStream() in servlet

Posted on 2002-07-21
4
826 Views
Last Modified: 2013-11-24
Hi,
I'm writing a program using Applet and servlet. I want my applet send an object to one servlet(say servlet1) and wait for reply. Then the applet sends another http text message to another servlet(say servlet2) depending on the reply from the previous servlet(servlet1). I do so by the following code. However, it doesn't work.

String line=null;
         
try{
log("sendAndRecvServlet1 connecting...");
URL url=new URL("http://127.0.0.1:8080/fyp/ErrChk1Servlet?templateName="+pac.getTemplateName());
URLConnection con=url.openConnection();
     
log("after URLConnection");
InputStream inputStream = con.getInputStream();
log("b4 inputStreamReader");
InputStreamReader inputStreamReader=new InputStreamReader(inputStream);

BufferedReader in = new BufferedReader(inputStreamReader);
while(true){
     line=in.readLine();
     if(line==null){
          break;
     }
     log(line);
}
in.close();
}
catch(Exception e7){
     log("e7");
}

The above code for sending a http text message to servlet2. I have closed the inputStream for connection of the first servlet(servlet1) b4 running the above code fragment.
It flows exception immediately after URLConnection. It seems that it cannot get the input stream.

Any ideas?

Thanks a lot...^^

Sherina
0
Comment
Question by:sherina
  • 2
4 Comments
 
LVL 3

Expert Comment

by:gandalf94305
ID: 7167587
Dear Sherina,
  it would really be helpful if you could disclose the nature of exception. My suspicion is that either the URL points to a server which is not running (Connection refused) or the template name you use as an argument does not represent valid URL syntax. Use java.net.URLEncoder.encode(pac.getTemplateName()) to be sure the syntax is correct.

Cheers,
--gandalf.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7167589
What you ought to do is to overload the log() method so that it can accept an exception as a parameter. You don't supply any details on this - can you do so?
0
 
LVL 3

Accepted Solution

by:
gandalf94305 earned 75 total points
ID: 7167592
Or, instead of writing log("e7"), write log("e7 " + e7);
0
 

Author Comment

by:sherina
ID: 7183069
i find the bug. Thanks a lot. I forgot to add info about this servlet in web.xml in Tomcat.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
basic hardware to learn oop advanced design patterns 3 88
Exception after setting jdbc session management 2 52
github account with ecipse 1 42
factorial example 4 34
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now