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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:26:29+00:00 2026-05-24T09:26:29+00:00

I am using Eclipse Helios with Struts and am having what I imagine is

  • 0

I am using Eclipse Helios with Struts and am having what I imagine is a rookie problem: for the life of me I have not been able to figure out why my jsp page will not acknowledge my business object .java file.

I think it has something to do with the .java class files as I have been unable to get them to appear in the IMPORTED CLASSES section under my Library Resources heading. The best I have been able to do thus far is load the class files as a seperate jar (which of course still doesn’t appear in the IMPORTED CLASSES section).

Does anyone know why my cart.jsp file refuses to allow me to reference my Cart.java business object? I get a null pointer error when I try to create the Cart, LineItem, and Product objects below.

Here are some snippets:

webapp\WebContent\example\cart.jsp

 <%@ page import="bo.*, java.util.ArrayList" %>
 <% 
    Cart cart = (Cart) session.getAttribute("cart"); 
    ArrayList<LineItem> items = cart.getItems();
    for (LineItem item : items)
    {
        Product product = item.getProduct();
 %>

   <tr valign="top">
     <td>
       <form action="<%=response.encodeURL("cart")%>" method="post">
         <input type="hidden" name="productCode" 
           value="<%=product.getCode()%>">
         <input type=text size=2 name="quantity" 
           value="<%=item.getQuantity()%>">
         <input type="submit" value="Update">
       </form>
    </td>
    <td>
 <%=product.getDescription()%>
    </td>
    <td>
 <%=product.getPriceCurrencyFormat()%>
    </td>
    <td>
 <%=item.getTotalCurrencyFormat()%>
    </td>
    <td>
       <form action="<%= response.encodeURL("cart")%>" method="post">
         <input type="hidden" name="productCode" 
           value="<%=product.getCode()%>">
         <input type="hidden" name="quantity" 
           value="0">
         <input type="submit" value="Remove Item">
       </form>
    </td>
 </tr><% } %>

Java Resources\src\bo\Cart.java

 package bo;

 import java.util.*;
 import java.io.Serializable;

 public class Cart implements Serializable
 {
     private ArrayList<LineItem> items;

     public Cart()
     {
         items = new ArrayList<LineItem>();
     }

     public void setItems(ArrayList<LineItem> lineItems)
     {
         items = lineItems;
     }

     etc. . . .      

Java Resources\src\bo\DisplayCartServlet.java

 package action;

 import java.io.*;
 import java.sql.SQLException;

 import javax.servlet.*;
 import javax.servlet.http.*;
 import org.apache.struts.action.*;

 import bo.*;
 import dao.*;

 public class DisplayCartServlet extends Action
 {
     public ActionForward execute(ActionMapping mapping, ActionForm form,      HttpServletRequest request,
        HttpServletResponse response)
        throws IOException, ServletException
     {

        String forward = new String("success");     ;
         String productCode = request.getParameter("productCode");      

         HttpSession session = request.getSession();

         Cart cart = (Cart) session.getAttribute("cart");  
         if (cart == null)
         {
            cart = new Cart();
            session.setAttribute("cart", cart);
         }

         int quantity = 1;

         // Get product from product code
         Product product=null;
    try {
        product = ProductDB.selectProduct(productCode);         
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
         session.setAttribute("product", product);

         // If product exists, add or remove from cart
         if (product != null)
         {
            LineItem lineItem = new LineItem();
            lineItem.setProduct(product);
            lineItem.setQuantity(quantity);
            if (quantity > 0)
              cart.addItem(lineItem);
            else
            cart.removeItem(lineItem);
          }
          session.setAttribute("cart", cart);

          return(mapping.findForward(forward));
     }

 }

Struts.xml declaration:

 <struts>

 <constant name="struts.enable.DynamicMethodInvocation" value="false" />
 <constant name="struts.devMode" value="false" />

   <package name="example" namespace="/example" extends="struts-default">

     <action name="cart" class="action.DisplayCartServlet" method="execute">
        <result name="success">/example/cart.jsp</result>
     </action>

   </package>
  . . . . 
  </struts>

Link that requests action/servlet:

 <div id="cartLink"><a href="<s:url action="cart?productCode=XM123456"/>">Add to Cart</a></div> 
  • 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-24T09:26:32+00:00Added an answer on May 24, 2026 at 9:26 am

    You expect a cart to be present in a (new) HttpSession. Given an HttpSession exists because you are running in tomcat/jetty and either of these servlet containers will create a session for you.

    Now you ask for a cart in that session. Why do you expect it to be there?

    Cart cart = (Cart) session.getAttribute("cart");
    

    You could create one if session.getAttribute(“cart”) returns null and store it in your session object.

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

Sidebar

Related Questions

I have a little problem with Tomcat. I'm using Eclipse Helios to luanch some
I've been using Eclipse with RDT (not RadRails) a lot lately, and I'm quite
I have been using Eclipse as an IDE for a short amount of time
I am using Eclipse Helios and JBoss 4.2.0. I have built a maven project
I have a strange problem with Eclipse (Helios). After a few hours of working
We are using Eclipse Helios as our IDE . We have a class in
I am using Eclipse Helios. Last days I am facing problem that Eclipse Helios
Using Eclipse Helios, I tried to start a JSF based project. After having created
Am using eclipse helios with m2eclipse plugin. For a maven project checked out from
I'm using Eclipse Helios and EGit 0.11.3. I have a project where different branches

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.