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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:03:59+00:00 2026-06-05T04:03:59+00:00

I’m inheriting a codebase that has largely JSP scriplets that quickly become less than

  • 0

I’m inheriting a codebase that has largely JSP scriplets that quickly become less than readable, for instance here’s the fragment that does pagination links:

Visa:
<a class="link" href="javascript:doSubmit('MenyNavigation', 'REW_<%= thisPage %>')" > 
   <%
     if(headPointer - nrOfHitsOnPage > 0){
         out.print(" << ");
         if(tailPointer - nrOfHitsOnPage <= 0 ){
             out.print(1);
         } else {
             out.print(tailPointer - nrOfHitsOnPage);
         }
         out.print("-");
         out.print(tailPointer);
      } %>
</a>
&nbsp;
<% if(resultListSize > 0 ) { %>
   <%=(tailPointer + 1)%> - <%= headPointer %>
<%}%>
&nbsp;
<a class="link" href="javascript:doSubmit('MenyNavigation', 'FWD_<%= thisPage %>')" > 
   <%   
     if(headPointer < resultListSize){
         out.print(1 + headPointer);
         out.print("-");                 
         if(headPointer + nrOfHitsOnPage > resultListSize){
             out.print(resultListSize);
         } else {
             out.print(nrOfHitsOnPage + headPointer);
         }
         out.print(" >> ");
      } %>
</a>

Appearantly this code displays the text “Display 1-10 of 20” when there are 10 elements per page and 20 in total and likewise for other settings but I think this solution is not very reusable. The code is already used in one place in our project and we decided that if we haveone solution for a problem we are going to use the same solution for the same problems if they appear in different places and now I must do pagination for > 5 popups(!) that have search functions and I wonder whether to use this code, to make an analgue solution or build from scratch.

The controller Java class has also not that high cohesion:

public class MenyNavigationActionHandler extends PandoraActionHandler {

    private ArendeProcessSessionData sessionData;
    private final static Logger logger = Logger
            .getLogger(MenyNavigationActionHandler.class);

    protected IFormData getFormData() {
        return null;
    }

    protected IFormPattern getPattern() {
        return EmptyFormPattern.getInstance();

    }

    protected void performAction(ISessionHandler sessionHandler, Action action) {

        String returnPage = null;       

        try {

            sessionData = (ArendeProcessSessionData) sessionHandler.getSessionData();

            if(sessionData.returnToUnsavedData(sessionHandler, action)){
                return;
            }


            if (sessionData.getMenuManager() == null) {

                MenuManager menuManager = new MenuManager();
                sessionData.setMenuManager(menuManager);
            }

            // Om man bläddar i träfflista på formell kontrollista
            if (action.getActionCommand().endsWith(ArendeProcessLocator.getFormellKontrollLista())) {

                FormellKontrollInfo fInfo = sessionData.getFormellKontrollInfo();
                FormellKontrollSearchAdmin fSearch = fInfo.getFormellKontrollSearchAdmin();

                if(fInfo != null) {

                    if (action.getActionCommand().startsWith("FWD")) {

                        fSearch.setDirection(PandoraConstants.FWD_DIRECTION);

                    } else if (action.getActionCommand().startsWith("REW")) {
                        fSearch.setDirection(PandoraConstants.REW_DIRECTION);

                    } else {
                        fSearch.setDirection(PandoraConstants.NO_DIRECTION);
                    }
                }

                returnPage = ArendeProcessLocator.getFormellKontrollLista();
                action.setReturnPage(returnPage);

            } else if (action.getActionCommand().equalsIgnoreCase(
                    ArendeProcessLabelConstants.SUB_MENU_VISA_REGISTRERADE)) {

                sessionData.setNyinkomnaLista(null);

                MenuManager menuManager = sessionData.getMenuManager();
                returnPage = menuManager.getLatestDestination(action.getActionTarget());

                if (returnPage == null) {

                    returnPage = action.getCurrPage();
                }

                action.setReturnPage(returnPage);

            } else {
                // Standard hantering av menyval. Target från Navigation-objekt hämtas från action.getActionModifier
                MenuManager menuManager = sessionData.getMenuManager();
                if(action.getActionTarget() != null && !action.getActionTarget().trim().equals("")){
                    returnPage = menuManager.getLatestDestination(action.getActionTarget());
                }else{
                    returnPage = menuManager.getLatestDestination(sessionData.getLatestActionTarget());
                }
                if (returnPage == null) {
                    returnPage = action.getCurrPage();
                }
                action.setReturnPage(returnPage);
            }

            if(action.getCurrPage().endsWith(ArendeProcessLocator.getNyregistrering())){
                   // Nytt önskemål, Kom ihåg innehållet på registrera sidan när vi går till listan  2010-12-02
                   sessionData.getNyregistrering().setKundReferens(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_KUNDREFERENS));
                   sessionData.getNyregistrering().setSokEfternamn(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_SOKEFTERNAMN));
                   sessionData.getNyregistrering().setSokFornamn(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_SOKFORNAMN));
                   sessionData.getNyregistrering().setForetag(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_FORETAG));
                   sessionData.getNyregistrering().setSokandeLandKod(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_SELECT_SOKANDELAND));
                   sessionData.getNyregistrering().setAnkomstDatum(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_ANKOMSTDAG));
                   sessionData.getNyregistrering().setOriginal("original".equals(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_HANDLINGSFORM))? true : false);
                   sessionData.getNyregistrering().setArendeNummer(sessionHandler.getRequestParameter(PandoraFieldConstants.FIELD_ARENDENUMMER));
                             //printer ??
             }

            if(!action.getCurrPage().endsWith(ArendeProcessLocator.getNyinkomnaLista2()) && action.getReturnPage().endsWith((ArendeProcessLocator.getNyregistrering()))){
                   // Rensa minnet av registrera sidan om det inte är listan med registrerade man kommer ifrån
                   sessionData.getNyregistrering().setKundReferens("");
                   sessionData.getNyregistrering().setSokEfternamn("");
                   sessionData.getNyregistrering().setSokFornamn("");
                   sessionData.getNyregistrering().setForetag("");
                   sessionData.getNyregistrering().setSokandeLandKod("");
                   sessionData.getNyregistrering().setAnkomstDatum("");
                   sessionData.getNyregistrering().setOriginal(true);
                   sessionData.getNyregistrering().setArendeNummer("");
             }

             if(action.getActionCommand().equals(ArendeProcessLocator.getNyinkomnaLista())){
                   sessionData.setNyinkomnaLista(null);
              }


        } catch (Exception e) {

            logger.error("MenyNavigationActionHandler: performAction() ", e);
        }

    }

} 

I have access to my colleague who write the code and can ask him to guide me what files I should have so the pagination will work but I want a clean and lean solution with no scriplets and that would be a lot of work starting this from scratch instead of using the scriplets.

What do you think I should do? Just use the scriplets above, make them work for my use case and then refactor the most I can to JSTL tags and EL? Any other comment how to reuse Java / JSP code for pagination? Our framework is rather special and custom and we are not using struts or spring or jsf but our own framework which kind of oomplicates things since it relies on session data much.

Any answer or comment is appreciated.

  • 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-05T04:04:00+00:00Added an answer on June 5, 2026 at 4:04 am

    I think it depends on how much of this code there is, and whether you have time to spend on making it more maintainable. I don’t think anyone but you (and your boss) can answer that question.

    On the question of how to implement this kind of thing, you can choose between the standard JSTL tag libraries or implementing your own, or a combination. And you can do more if you combine taglibs with EL. And session attributes shouldn’t be a particular problem.

    One piece of advice though. JSTL and JSP EL are getting more expressive, so it could be worthwhile upgrading to a servlet container that implements a recent edition of the Servlet specs.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

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.