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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:20:20+00:00 2026-06-17T12:20:20+00:00

I am using Struts 2 and Freemarker. This is my action class: package test;

  • 0

I am using Struts 2 and Freemarker. This is my action class:

package test;

import java.util.ArrayList;
import java.util.List;

public class WelcomeAction {
    
    private String userName;
    private String gender;
    private List<String> fruits;
    private String fruit;


    public String execute() {
//      if(!userName.equals("a"))
//      {
//          return "fail";
//      }
//      else {
//          return "SUCCESS";           
//      }
        return "SUCCESS";
    }   
    
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    
    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getFruitsPicked() {
        return fruit;
    }

    public void setFruitsPicked(String fruitsPicked) {
        this.fruit = fruitsPicked;
    }

    public List<String> getFruits() {
        return fruits;
    }

    public void setFruits(List<String> fruits) {
        this.fruits = fruits;
    }
    
    public WelcomeAction(){
        fruits = new ArrayList<String>();
        fruits.add("apples");
        fruits.add("oranges");
        fruits.add("pears");
        fruits.add("peaches");
    }
}

This is what I have in my .ftl:

<input type="checkbox" list="fruits" name="friut[]" value="apples" /> Apples<br /> 
<input type="checkbox" list="fruits" name="friut[]" value="oranges" /> Oranges<br /> 
<input type="checkbox" list="fruits" name="friut[]" value="pears" /> Pears<br /> 
<input type="checkbox" list="fruits" name="friut[]" value="peaches" /> Peaches<br />

This is how I tried printing:

<#list fruits as item>${item}</#list>

But above command prints all the items in my list that I added in my constructor. Of course, I only want the items that were checked when the form was submitted.

  • 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-17T12:20:21+00:00Added an answer on June 17, 2026 at 12:20 pm

    name="friut[]" should be name="fruits". The JavaBean property name is fruits, not fruit (nor friut… note the typo). I don’t know about that [] is meaningful for Struts, better said, for OGNL/ValueStack.setValue that the ParametersIntercaptor uses. (It understands fruits[0] though, which is useful to set an element in an existing list.). So at the end Struts has ignored the parameters, so you end up with the original list. Where does list="fruits" come from?

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

Sidebar

Related Questions

Using Struts 2, I have this interceptor: public class AccessInterceptor extends AbstractInterceptor { @Override
I have been using struts-errors to pass messages from dispatch action class to view
I am using Struts and Java. The problem is that I have a page
I'm working to create an java web apps using Struts and a Cassandra DB.
I'm using Freemarker as the templating engine for a Struts 2 application and having
I am using struts, I have a java web application which needs to run
I iterate a list using Struts 2 tags. <s:iterator value=popUpScreenDetailsList status =rowCounter> //do something
I am using struts 1.2.I want to enter the request parameters and action called
I am using Struts + Velocity in a Java application, but after I submit
I'm using struts. My ActionForm has an ArrayList set up within it, how can

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.