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

  • Home
  • SEARCH
  • 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 592923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:47:27+00:00 2026-05-13T15:47:27+00:00

I’ve encountered a problem with JSP pages server-side caching. Suppose I have an internal

  • 0

I’ve encountered a problem with JSP pages server-side caching.

Suppose I have an internal error page which is a custom JSP that will display a unique ID each time it’s visited/requested. This unique ID is also logged in the server log for debugging. However, I noticed that if I implement the error ID using:

<%!private String <b>abc</b> = UUID.randomUUID().toString();%>

After a few requests…the variable abc seems to be cached on the server side and the same value keep poping up.

Oddly enough, on the same page, I also display the time in which the error is encountered with

XXXError encountered on <%=Calendar.getInstance().getTime().toString()%>

which never gets cached and always display the current time.

So I did a little experiment, instead of displaying time using the above, I used

<%!private String etime = Calendar.getInstance().getTime().toString();%>

and print onscreen that string, and SNAP, it’s getting cached after a few calls.

So my question is, how do I stop the server from caching these variables?

  • 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-13T15:47:27+00:00Added an answer on May 13, 2026 at 3:47 pm

    Roughly translated, this is been declared as instance variable of the servlet class which the JSP page at end get compiled to. E.g.

    public class pagename_jsp_servlet extends HttpServlet {
        private String abc = UUID.randomUUID().toString();
    
        protected void service(HttpServletRequest ...
    

    As JSPs usually get compiled only once during startup (or after change, if hotdeploy at server is enabled), the very same servlet instance will be shared among all requests! You don’t want to do that.

    After all, you should not be using scriptlets in JSP pages. Java code belongs in a real Java class. In this particular case you could use an EL function, or a bean class, or a servlet class.

    The EL function would finally look like this:

    <c:set var="uuid" value="${uuid:random()}" />
    <p>UUID: ${uuid}</p>
    

    A bean class would look like this:

    public class UUIDBean {
        public String getRandom() {
            return UUID.randomUUID().toString();
        }
    }
    

    which can be used as:

    <jsp:useBean id="uuid" class="com.example.UUIDBean" />
    <p>First UUID: ${uuid.random}</p>
    <p>Next UUID: ${uuid.random}</p>
    

    A servlet class should be mapped on an url-pattern covering the JSP page (or vice versa) and should have the doGet() method implemented to preprocess requests before displaying data in a JSP page:

    UUID uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
    request.getRequestDispatcher("page.jsp").forward(request, response);
    

    the forwarded JSP page can look like this:

    <p>UUID from servlet: ${uuid}</p>
    

    Further, the <%=Calendar.getInstance().getTime().toString()%> is better to be replaced as follows:

    <jsp:useBean id="now" class="java.util.Date" />
    <p>The date is now: ${now}
    <p>The date in yyyy-MM-dd format: <fmt:formatDate value="${now}" pattern="yyyy-MM-dd" />
    

    It keeps the code much cleaner and better maintainable.

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

Sidebar

Ask A Question

Stats

  • Questions 312k
  • Answers 312k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Step #1: Pull that row out into a separate layout… May 13, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer There's no states in between hidden and non-hidden. How to… May 13, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer In the event for KeyDown, you can check if the… May 13, 2026 at 10:41 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.