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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:58:46+00:00 2026-06-01T14:58:46+00:00

My application has the following patterns: a FrontController, Command, Service, and DAO. The problem

  • 0

My application has the following patterns: a FrontController, Command, Service, and DAO.

The problem im having is that I want to display a list of users (and their avatars) on my homepage. How do I get my jsp page to automatically call the ListMembersCommand upon page load without a get/post request?

  • 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-01T14:58:48+00:00Added an answer on June 1, 2026 at 2:58 pm

    You don’t. What you do is you call the controller and have if forward to the JSP. You never call the JSPs directly themselves.

    So, what you end up with is:

    request --- invokes ---> Controller --- forwards to ---> JSP
    

    The Controller can fetch whatever is necessary and populate the request appropriately before called the JSP to render it all.

    Addenda –

    Here is a simple Servlet, mapped to /MyServlet :

    public class MyServlet extends HttpServlet {
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            MemberDAO dao = DAOFactory.getMemberDAO();
            List<Member> members = dao.getMembers();
            request.setAttribute("members", members);
            RequestDispatcher rd = getServletContext().getRequestDispatcher("/WEB-INF/jsp/members.jsp");
            rd.forward(request, response);
        }
    }
    

    And here is an associated JSP placed at /WEB-INF/jsp/members.jsp:

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Members List</title>
        </head>
        <body>
            <h1>Members List</h1>
            <table>
                <tr>
                    <td>Member ID</td>
                    <td>First Name</td>
                    <td>Last Name</td>
                </tr>
                <c:forEach items="${members}" var="member">
                    <tr>
                        <td>${member.id}</td>
                        <td>${member.firstName}</td>
                        <td>${member.lastName}</td>
                    </tr>
                </c:forEach>
            </table>
        </body>
    </html>
    

    In your browser, you hit: http://yourhost/yourapp/MyServlet

    The servlet, acting as a controller, takes the request, acts on it (in this case getting a list of all of the members from the database using a simple DAO pattern), and then puts the results in to the request with the tag “members” (the request.setAttribute("members", members) does this).

    One the request is properly populated with interesting information, the servlet forward to the JSP.

    Note in this case the JSP is located below the WEB-INF directory. JSPs located within WEB-INF are NOT accessible at all from the browser. So a request to http://yourhost/yourapp/WEB-INF/jsp/members.jsp will simply fail.

    But they are accessible internally.

    So, the Servlet forwards to members.jsp, and members.jsp renders, locating the members value from the request (${members} in the JSTL c:forEach tag), and the c:forEach iterates across that list, populating the member variable, and from there filling out the rows in the table.

    This is a classic “controller first” pattern which keeps the JSP out of the way. It also helps maintain that the JSPs only live in the View layer of MVC. In this simple example, Member and the List is the model, the Servlet in the Controller, and the JSP is the view.

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

Sidebar

Related Questions

Our application has a service layer and a DAO layer, written as Spring beans.
I'm building WPF client application. I'm following MVC pattern. The project solution has many
My android application has several warnings of the following form when I run it
Our application has many controls that are created dynamically. For example, a navigation pane
My application has a table that contains snapshot inventory data from each year. For
My application has encountered a problem and needs to close. Of course Microsoft is
I have used an Android application recently that has an interesting UI pattern in
We have a client application where the users want to search notes fields for
I do not want Auditing or History tracking. I have an application that pulls
Actually I have a serious problem : I saw that somebody has accessed my

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.