scriplet in jsp does not work

Dear experts
I have this code in my java action class which works fine

 BufferedReader in =new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String line;
               StringBuffer lines = new StringBuffer();
               String linefeed = "\n";              
               while((line = in.readLine()) != null) {
               HttpSession session = request.getSession();

***** System.out.println(lines.toString()); works fine and i can see the result in the console. but i want to print the
same result in the jsp page but its not working . I am setting "in"(BufferedReader) in session and calling in jsp

******I have the above code as a scriplet in my  jsp page


  StringBuffer lines = new StringBuffer();
if(session.getAttribute("result") != null)
BufferedReader in = (BufferedReader)session.getAttribute("reportresult");

               String line;
               String linefeed = "\n";              
               while(line = in.readLine() != null)

In the above jsp scriplet I can see 111111  BUT 22222  is not getting displayed at all since  
while(line = in.readLine() != null)   is not getting executed but the same works fine in java program and shows result in

any help greatly appreciated
LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


you should be doing this...

are you doing like below example ?

Socket s = new Socket(..)
session.setAttribute("socket", s);
session.setAttribute("socketIn", new BufferedReader(new InputStreamReader(s.getInputStream())));
session.setAttribute("socketOut", new PrintWriter(new OutputStreamWriter(s.getOutputStream())));

BufferedReader in = (BufferedReader)session.getAttribute("socketIn");
PrintWriter out = (PrintWriter)session.getAttribute("socketOut");

jaggernatAuthor Commented:

I am just creating instance of BufferedReader

BufferedReader  in =new BufferedReader(new InputStreamReader(connection.getInputStream()));

setting "in"   in session and trying to call that in jsp page ,but unable to do it

this segment scriplet of code  does not work in jsp

BufferedReader in = (BufferedReader)session.getAttribute("result");  //WORKS

               String line;
               String linefeed = "\n";              
               while(line = in.readLine() != null) // DOES NOT WORK
Mick BarryJava DeveloperCommented:
>      session.setAttribute("result",in);
> BufferedReader in = (BufferedReader)session.getAttribute("reportresult");

firstly you are using the wrong name to get the reader,you set it as result and retrieve it as reportresult

Secondly you have already read the complete conntents of your stream in yoiur action so there is nothing left to read, it is already at eof.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.