scriplet in jsp does not work

Posted on 2006-04-19
Last Modified: 2008-03-17
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
Question by:jaggernat
    LVL 23

    Assisted Solution


    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");

    LVL 10

    Author Comment


    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
    LVL 92

    Accepted Solution

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    759 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

    14 Experts available now in Live!

    Get 1:1 Help Now