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 7908985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:11:21+00:00 2026-06-03T12:11:21+00:00

I have a basic app in SpringMVC. All of my controllers extend a super

  • 0

I have a basic app in SpringMVC. All of my controllers extend a super class shown below.
The problem here is that the cssFiles and jsFiles are not reset every time a controller method is touched. So I end up with content/view.js being loaded x+1 times for every page view. If I’ve loaded the page 3 times, it’ll contain 4x content/view.js files.

I’m seeing these values be appended to each time the page is loaded. Why is this happening and how do I fix it?

public class Controller {
    private List<String> cssFiles = new ArrayList<String>();
    private List<String> jsFiles = new ArrayList<String>();

    public Controller () {
        this.addCss("global");

        this.addJs("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min");
        this.includejQueryUI();
        this.addJs("global");
    }

    public ModelAndView prepareModel (ModelAndView model) {

        model.addObject("cssFiles", cssFiles);
        model.addObject("jsFiles", jsFiles);

        return model;
    }
    public ModelAndView prepareModel (ModelAndView model, String title) {
        model.addObject("title", title);

        return prepareModel(model);
    }

    /*
     * Add a css file to the page
     */
    public void addCss (String cssPath) {
        if (cssPath.indexOf("://") < 1) {
            cssPath = "/cmt/css/"+cssPath;
        }

        cssFiles.add(cssFiles.size(), cssPath);
    }

    /*
     * Add a javascript file to the page
     */
    public void addJs (String jsPath) {
        if (jsPath.indexOf("://") < 1) {
            jsPath = "/cmt/js/"+jsPath;
        }

        jsFiles.add(jsFiles.size(), jsPath);
    }

    /**
     * Add a Rich Text Editor (TinyMCE) library to the page
     */
    public void includeRichTextEditor() {
        addJs("../lib/tiny_mce-3.5b3/tiny_mce");
    }

    /**
     * Add the jQuery UI library to the page
     */
    public void includejQueryUI() {
        addCss("../lib/jquery-ui-1.8.19/custom-theme/jquery-ui-1.8.19.custom");
        addJs("../lib/jquery-ui-1.8.19/jquery-ui-1.8.19.custom.min");
    }
}

I’m still struggling to determine the cause of this issue…. any ideas?

Part of web.xml

<!-- Standard spring configuration -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

<!-- Spring Web MVC dispatcher servlet -->
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.html</url-pattern>
    <url-pattern>*.json</url-pattern>
</servlet-mapping>
  • 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-06-03T12:11:24+00:00Added an answer on June 3, 2026 at 12:11 pm

    Although I didn’t test this code, the obvious thing what I’d try is :

    public class Controller {
        private List<String> cssFiles;
        private List<String> jsFiles;
    .......
     public Controller () {
            cssFiles = new ArrayList<String>();
            jsFiles = new ArrayList<String>();
            this.addCss("global");
            this.addJs("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min");
            this.includejQueryUI();
            this.addJs("global");
        }
    

    Can you ellaborate what you mean by reset in are not reset every time a controller method is touched

    I’ve misunderstood your question at first here is revised version :

    <html>
    <head>
    <!--Above content is header-->
    <!--Specific CSS for edit.jsp here-->
    <!--Or if you want to override css classes inside <style></style>-->
    </head>
    <body>
    <!--Load specific edit.jsp javascript at the end of the body tag-->
    <!--Below content is footer-->
    </body>
    </html>
    

    If you need to override some javascript then put the edit.jsp specific js after the html tag. So your edit file would look like this :

    <%@include file="header.jsp" %>
    </head>
    <body>
    <!--some edit.jsp content -->
    <%@include file="footer.jsp" %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic doubt regarding the method that gets executed when app
Well, I think I have a very basic doubt here: I'm developing an app
I have a basic class that derived subclasses inherit from, it carries the basic
I have a basic app that allows user1 to create a redeemable code. user1
I have a basic Node.js app that I am trying to get off the
I have a pretty basic app flow that is quite linear, so it fits
I have a basic Ruby app that I am building with Sinatra, Datamapper and
I have a basic directory app that works fine except that it seems to
Ok I have a basic iPad app that asks for 5 search/filter criteria from
actionmailer actionpack activeresource activesupport I have a basic scaffolded CRUD app that uses ActiveRecord

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.