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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:36:46+00:00 2026-05-24T16:36:46+00:00

Well, basically my struts servlet isn’t working right. Please tell me if anything appears

  • 0

Well, basically my struts servlet isn’t working right. Please tell me if anything appears wrong below:

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

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
    <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" >
                      <result name="success">/example/cart.jsp</result>
                    </action>        

                </package>
     </struts>

listProducts.jsp link that activates the struts and 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-24T16:36:47+00:00Added an answer on May 24, 2026 at 4:36 pm

    Your application isn’t working correctly because you have created a Struts 1 Action class but you are trying to configure it with a Struts 2 configuration XML.

    Struts 1 and Struts 2 are very different.

    Struts 1 Configuration is called struts-config.xml: http://struts.apache.org/dtds/struts-config_1_3.dtd

    Struts 2 configuration is called struts.xml: http://struts.apache.org/dtds/struts-2.0.dtd

    You created a Struts 1 Action class (which as @BalusC pointed out, is not a Servlet) so you must configure it using struts-config.xml…

    Or,

    … you have to create a Struts 2 class to match the struts.xml configuration.

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

Sidebar

Related Questions

the jQuery tablesorter plugin isn't working too well for one specific case. Basically, I
Well basically I've got a vb.net script connecting to IRC, and I'm working on
Well I am working on a site that basically accepts PayPal payments to give
well right now I basically have the jquery load function like this $('#results').load(sources.php?source=1&page=<?=$_GET['page']?>&search=<?=$_GET['search']?>); so
Well basically I have this script that takes a long time to execute and
Well the subject is the question basically. Are there any version control systems out
Well... simple question, right? But with no so simple answers. In firefox i use
Well basically I may want to execute a script that may take as much
Well basically I want to record the uri which produces an error when testing,
well i basically cant add an app.config file to my win forms project. and

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.