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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:07:13+00:00 2026-05-21T02:07:13+00:00

Basically, I want to display the products in an ArrayList on a JSP page.

  • 0

Basically, I want to display the products in an ArrayList on a JSP page. I have done that in the servlet code. But theres no output.

Also Do I have to place products.jsp in the /WEB-INF folder? When I do that, I get a requested not resource error.

My Servlet Code (InventoryServlet.java)

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    try {
        List<Product> products = new ArrayList<Product>();
        products = Inventory.populateProducts(); // Obtain all products.
        request.setAttribute("products", products); // Store products in request scope.
        request.getRequestDispatcher("/products.jsp").forward(request, response); // Forward to JSP page to display them in a HTML table.
    } catch (Exception ex) {
        throw new ServletException("Retrieving products failed!", ex);
    }

}

My JSP Page (products.jsp)

<h2>List of Products</h2>

<table>
    <c:forEach items="${products}" var="product">
       <tr>
           <td>${product.Description}</td>
          <td>${product.UnitPrice}</td>
       </tr>
    </c:forEach>
</table>

Web.xml

<web-app version="3.0"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

 <servlet>
   <servlet-name>Inventory</servlet-name>
   <servlet-class>com.ShoppingCart.InventoryServlet</servlet-class>
 </servlet>
 <servlet-mapping>
    <servlet-name>Inventory</servlet-name>
    <url-pattern>/products</url-pattern>
  </servlet-mapping>
</web-app>
  • 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-21T02:07:14+00:00Added an answer on May 21, 2026 at 2:07 am

    You need to open the page by requesting the servlet URL instead of the JSP URL. This will call the doGet() method.

    Placing JSP in /WEB-INF effectively prevents the enduser from directly opening it without involvement of the doGet() method of the servlet. Files in /WEB-INF are namely not public accessible. So if the preprocessing of the servlet is mandatory, then you need to do so. Put the JSP in /WEB-INF folder and change the requestdispatcher to point to it.

    request.getRequestDispatcher("/WEB-INF/products.jsp").forward(request, response);
    

    But you need to change all existing links to point to the servlet URL instead of the JSP URL.

    See also:

    • Servlets info page
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a financial calculator in MS excel, and I basically want to display
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
So I basically want to have a static method in my AR class to
I have a 2-dimensional array of objects and I basically want to databind each
I have an SPListItemCollection. I basically want to get one of the items (randomly)
On the home page of my site I want to display a lot of
Ok here it is. i have two tables: products and product_sizes so basically my
I have a question related to jquery. Basically I want to do a very
What I basically want to do is tp display a sequence of images at
I'd like a page blocking/loading script that will overlay the entire page and display

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.