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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:20:48+00:00 2026-05-23T23:20:48+00:00

What is the best-practice for developing web-pages for both non-JS-enabled and JS-enabled pages? I

  • 0

What is the best-practice for developing web-pages for both non-JS-enabled and JS-enabled pages? I am developing a Spring MVC web-application using JSP/JSTL as the view technology.

The way I work is to create a full web-page (with “html”, “head”, etc) tags in it. This will work on all browsers. My entire app works (however ugly-bugly) with JS disabled.

Also included in each page is some jQuery script that prettifies the page, typically turning top-level “divs” into tabs, other divs into dialogs, etc. The JS “hijacks” the underlying HTML. My JS hijacks the links and buttons, using AJAX calls to load the content into the correct dialog or tab div.

This all works nicely and I like the architecture, but I have added an optimisation such that the AJAX requests appends a “contentOnly” parameter; this is picked up by the Spring MVC view which conditionally ignores the “head”, etc – i.e. it only renders the real content that the AJAX version wants. It just feels clunky.

I know I could load the entire page and discard the outer bits but this seems inefficient to load all the associated CSS and JS files which are not strictly necessary.

My question is: is there a nicer way to write this conditional formatting, should I be using a different view technology or something else, something like Velocity or FreeMarker or whatever Grails uses?

An example of my conditional: –

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<c:if test="${param.contentOnly == null}">
<!DOCTYPE html>
<html>
<head>
    <%@ include file="_stylesAndScripts.jsp"%>
    <title>My App Title</title>
</head>

<body>
    <%@ include file="_header.jsp"%>
    <%@ include file="_menu.jsp"%>
</c:if>
    <div id="leadListPanel" class="contentPanel">
        <h1>My App Title</h1>
        <p>The time on the server is ${serverTime}.</p>

        <table id="leadTable" class="list">
                    ... rest of content...

<c:if test="${param.contentOnly == null}">

    <%@ include file="_footer.jsp"%>
</body>
</html>
</c:if>
  • 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-23T23:20:50+00:00Added an answer on May 23, 2026 at 11:20 pm

    You need to include the files the other way round.

    /WEB-INF/template.jsp

    <!DOCTYPE html>
    <html>
        <head>
            <%@ include file="_stylesAndScripts.jsp"%>
            <title>My App Title</title>
        </head>
        <body>
            <%@ include file="_header.jsp"%>
            <%@ include file="_menu.jsp"%>
            <jsp:include page="${page}.jsp" />
            <%@ include file="_footer.jsp"%>
        </body>
    </html>
    

    leads.jsp

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <div id="leadListPanel" class="contentPanel">
        <h1>My App Title</h1>
        <p>The time on the server is ${serverTime}.</p>
    
        <table id="leadTable" class="list">
                    ... rest of content...
    

    And create a controller which sets leads as ${page} variable based on a specific request URL and forward to template.jsp instead. Since I don’t do Spring, I can’t answer in detail how to achieve it with Spring. But the following basic JSP/Servlet kickoff example should give the general idea:

    @WebServlet(urlPatterns={"/pages/*"})
    public class TemplateServlet extends HttpServlet {
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String page = request.getPathInfo();
            // .. Do some other preprocessing if necessary .. and then:
            request.setAttribute("page", page);
            request.getRequestDispatcher("/WEB-INF/template.jsp").forward(request, response);
        }
    
    }
    

    Invoke it as http://example.com/contextname/pages/leads to get the template displayed with leads.jsp included. Finally you should be able to invoke http://example.com/contextname/leads.jsp independently to get the sole template content.

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

Sidebar

Related Questions

We are developing a new web service and are looking into the best practice
I am developing a medium size Java Web Application with Struts as MVC framework
I'm developing web application using CodeIgniter. All this time, I put the custom js
What's the best practice for making sure that certain ajax calls to certain pages
What's the best practice for using a switch statement vs using an if statement
We are in the process of developing a .NET based IIS hosted web application
The ASP.NET web application I am developing needs to support two different types of
We as a group develop Javascript/JSP web application, and the problem is we are
I'm developing a DAO using Spring JdbcDaoSupport and would like to know if anyone
I am developing an iPad application which supports both landscape as well as portrait

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.