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?
>      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.

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.