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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:11:07+00:00 2026-05-25T20:11:07+00:00

I’m a beginner in JSP. While developing a web application for a sample scenario,

  • 0

I’m a beginner in JSP. While developing a web application for a sample scenario,
I came across this subtlety.

I have the following pages:

  • index.jsp
  • login.jsp (and LoginServlet.java)
  • account.jsp

To facilitate code reuse I divided all pages into 3 parts – menu-header, content, footer.

For all the above pages, menu-header and footer remains the same, only the content changes.
So, I created menuandheader.jsp and footer.jsp to be included into every page.
index.jsp = (menuandheader.jsp+content+footer.jsp)

Now I have 5 different user roles thus, 5 different index and account pages. (again for these pages only the content area changes).

I created a Filter class for LoginServlet.java which takes care of authentication and stores the appropriate page name as a request attribute. (index1.jsp for role #1 and so on) Now the only contents of LoginServlet.java is

dispatch = request.getRequestDispatcher(request.getAttribute("page").toString());
dispatch.forward(request, response);

But in this approach I need to have 5 almost similar index and account pages. Is there a better way to deal with this scenario?

  • 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-25T20:11:08+00:00Added an answer on May 25, 2026 at 8:11 pm

    Let’s first look at the downsides of your approach

    1. If you want to add a new role then, You need develop/build/deploy
    2. Your tightly coupling your business requirement (role based access) to your implementation causing a change to implementation on a change to requirment

    I would say a better approach would be to solve the problem on hand (i.e. restrict resource access based on user role). You can do this in many ways, Here is one way you could solve the problem

    1. Keep one index.jsp page
    2. Based on the role restrict access, If it is content or hyper link to different resource just hide it (you can do this with simple jsp tag)
    3. You could also benfit from using a framework (spring, struts, jsf etc), They provide good MVC implementation
    4. In index.jsp, you could do some thing like this, I used simple jstl tag in the example

      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
      
      <c:if test="${role.admin == true}">
          only admin could see this content
      </c:if>
      
       <c:if test="${role.supervisor == true}">
       <a href="">only supervisor's link</a>
       </c:if>
      
        every one can see this content
      

    I just gave you a simple approach to solve this problem, I would let you choose what the best option would be based on your requirement, I would say keep the implementation loosely coupled and easily extendable.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to loop through a bunch of documents I have to put
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.