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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:40:57+00:00 2026-06-10T04:40:57+00:00

I have a struts2 action class which looks something like this: //import relevant packages

  • 0

I have a struts2 action class which looks something like this:

//import relevant packages

public class Product implements SessionAware, ServletRequestAware,
        ServletResponseAware, ServletContextAware {

    private String productName;
    private String description;
    private String price;

    private ServletContext servletContext; 
    private HttpServletRequest servletRequest; 
    private HttpServletResponse servletResponse; 
    private Map sessionMap;

    //getters and setters here

    public void setServletRequest(HttpServletRequest servletRequest) {
        this.servletRequest = servletRequest;
    }

    public void setSession(Map map) {
        this.sessionMap = map;
    }

    public void setServletResponse(HttpServletResponse servletResponse) {
        this.servletResponse = servletResponse;
    }

    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    public String execute() {


       //  do something here
        return "success";
    }

    public List<String> getCountries() {
        List<String> countries = new ArrayList<String>();
        countries.add("Australia");
        countries.add("Fiji");
        countries.add("New Zealand");
        countries.add("Vanuatu");
        return countries;
    }

}

sruts.xml has the following contents:

<?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="true" />
    <package name="package.name" namespace="/" extends="struts-default">
        <action name="Product_input">
            <result>/jsp/Product.jsp</result>
        </action>
        <action name="Product_save" class="package.name.Product" method="execute">
            <result>/jsp/Details.jsp</result>
        </action>       
    </package>
</struts>

Product.jsp consists of a simple form:

<s:form action="Product_save">
        <s:textfield label="Product Name" key="productName"/>
        <s:textfield label="Description" key="description"/>
        <s:textfield label="Price" key="price"/>
        <s:submit/>
</s:form>

Details.jsp displays the contents entered in the form:

<h5>Details:</h5>
Product Name:
<s:property value="productName" />
<br /> Description:
<s:property value="description" />
<br /> Price: $
<s:property value="price" /> </br>
<s:property value="countries[0]" /> </br>

The last line in Details.jsp tries to access the countries list declared in the getCountries() in action class and ideally it should not print anything since the method is never accessed nor the countries list is part of the action class attributes (and hence while creating the object of type Product in the Value stack, it shouldn’t have countries).

But it does print Australia (the indexed value of list) along with the other form properties. How/Why is this happening?

  • 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-10T04:40:58+00:00Added an answer on June 10, 2026 at 4:40 am

    When you write countries in

    countries[0]
    

    it calls for getCountries() method. Now as you’ve put [0] next to it and countries being a list…

    it translates to

    getCountries().get(0)
    

    You can verify the same by putting a sysout in the getCountries() method.

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

Sidebar

Related Questions

I have this code for login validation using a Struts2 action class which calls
Hi I have something like this in struts.xml <action name=LoginAction class=controller.LoginAction> <result name=error>/Error.jsp</result> <result
I have a model-driven Struts Web action: public class ModelDrivenAction<T extends Object> implements ModelDriven<T>,
I am working on struts2. In my action class I have written some accessors
I have a simple Action class which I want to unit test: package com.gam.action.test;
I am working on struts2 application. I have getter/setter in my action class. Now,
Struts2 Actions normally extend ActionSupport class which implements of TextProvider interface and provides access
I have a Struts2 action in the server side for file downloading. <action name=download
In my struts.xml I have: <action name=file_save method=fileSave class=FileActionBean> <interceptor-ref name=fileUpload> <param name=maximumSize> 5242880
I have a struts2 web application which accepts both POST and GET requests in

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.