Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 684109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:46:49+00:00 2026-05-14T01:46:49+00:00

I have this jsp client that consumes a webservice. The problem with the client

  • 0

I have this jsp client that consumes a webservice. The problem with the client is whenever it calls the webservice and retrieves the result, it appends the result to the previous call’s result and displays it. But, if i redeploy the war file, the result appears fine. (only for the first time though)

Here’s the code without the import statements.

<html>
    <body>
        <%! public static Reader fr; %>
        <%! public static StringBuffer sb; %>
        <%! private static final int BLKSIZ = 8192; %>
        <%! public static String file, output; %>


        <%

        FileparserService service = new FileparserService();
        Fileparser port = service.getFileparserPort();

        sb = new StringBuffer();
        char[] b = new char[BLKSIZ]; 
        int n; 

        try {
            fr = new FileReader(<file>);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

         while ((n = fr.read(b)) > 0)   
            sb.append(b, 0, n); 

        file = sb.toString();

        output = port.getRanks(file);


        %>
        The final output is <br/>
            <%out.print(output); %>
    </body>
    <% fr.close(); %>
</html>

Thanks,
Deepak.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:46:50+00:00Added an answer on May 14, 2026 at 1:46 am

    First:

    <% (all raw java code) %>
    

    This is bad practice. It belongs in a real Java Class. JSP is a view technology providing a template for HTML/CSS/JS and the ability control page flow and interact with backend Java code using taglibs and access backend data using EL. This particular code needs to be done (in)directly in a class which extends HttpServlet.

    Back to your problem: although you declared static variables in a JSP page (of which there’s only one instance during webapp’s lifetime!!), you reinstantiate them all on every request. The obvious thread safety issues aside, the root cause of your problem is not in the posted code, in spite of the static variables. The only thing which look suspicious is the following line:

    output = port.getRanks(file);
    

    Doesn’t the getRanks() method do something with a static variable of the FileParser class? The chance is big when I look at the coding style/approach of the JSP. Maybe the method is appending the value to a static variable everytime without reinstantiating it (or better, without just declaring it threadlocal inside the method block) and then returning it? That would explain the problem you’re facing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JSP code snippet: <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%> <c:choose> <c:when test=${var1.properties[\Item Type\]
I have this jQuery code in my JSP page (jQuery 1.7.2) : function Header()
I have this strange behavior in my JSP page: I have two Integer variables
i have this tag as input tag: <a href=controller.jsp?sid=127490C88DB5&R=35144 class=11-link-dkred-bold><b>Mr. John Q. Anderson&nbsp;&nbsp;&nbsp;MBA 1977
So I am pretty new to JSP. I have tried this a few ways.
Still learning JSP Web Applications here. I have been doing this for a while
I have a custom jsp tag like this: <a:customtag> The body of the custom
I have a JSP page at an address like this: http://example.com/foo/bar/rawr/something.jsp When I output
I have a jsp page, which imports another jsp. This import is wrapped into
I have a webpage that makes an ajax call to get some data. That

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.