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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:56:05+00:00 2026-05-28T19:56:05+00:00

So, I have next situation: I have a page with form -> this form

  • 0

So, I have next situation:

I have a page with form -> this form submitted to the server -> On the server, present special struts 2 Action for processing submitted form -> and on the last step for user show again this page with form.

when, I try testing this workflow I see one strange for me moment:

When I first time open page – form fields – empty, but after submitted form on the server and reload page – fields – not empty! Fields contains data, that I fill on previous steps.

Here my test Action:

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

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class TestAction extends ActionSupport {

    private List<Integer> books;
    private String title;
    private String description;

    public List<Integer> getBooks() {
        return this.books;
    }

    public void setBooks(List<Integer> books) {
        this.books = books;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    private static final long serialVersionUID = 1L;

    public String show() {

        // filling books variable

        List<Integer> l = new ArrayList<Integer>();

        l.add(1);
        l.add(2);
        l.add(3);

        this.books = l;
        return Action.SUCCESS;
    }

    public String save() {

        // processing title and description variables here!

        return show();

    }

}

My test jsp file:

<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<body>

    <s:property value="books" />


    <s:form action="saveAction">
        <s:textfield id="title" label="Title" name="title" />
        <s:textfield id="description" label="Description"
            name="description" />
        <s:submit />
    </s:form>


</body>
</html>

And this small part my struts.xml with action tags:

    <action name="showAction" class="action.TestAction" method="show">
        <result>pages/test.jsp</result>
    </action>

        <action name="saveAction" class="action.TestAction" method ="save">
        <result>pages/test.jsp</result>
    </action>

so, I start investigate this problem, and what I have in result:

Action class instantiate only one time, and after all user request work with this instance of Action class.

so, if in my Action class I have few action methods – all this methods have access to all fields.

It is a good idea?

for example: user send request to the my Action.remove method with some id.

Next, user send request to the my Action.add method but without id parameter. – this situation must be failed! (for example – I forget add Validation).

but – nothing wrong – action instance contains value for field id.

So, my general question next:

1. One Action Class – One Method – it is the best practice?

2. If used few methods in one Action – I need add some service methods for clear modified fields? Or what I must do in this case?

Thanks!

  • 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-28T19:56:06+00:00Added an answer on May 28, 2026 at 7:56 pm

    The only way you’d get a single instance of an action class is if (a) you’re using Spring, and (b) your actions are declared as default (singleton) scope. Otherwise, without Spring or with prototype scoping, you’ll always get a new action instance per-request.

    1) It depends. I tend to lump tightly-coupled action methods into a single action class, but I don’t know as it’s a “best practice” or not–I think it depends on the situation and preference. I don’t see many compelling technical benefits to one over another.

    For me it’s a matter of readability and functional locality.

    2) Your configuration is almost certainly wrong if you’re getting the exact same action instance over multiple requests–I’d fix that before doing much else.

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

Sidebar

Related Questions

I have next situation: I should allow to see Add Rendering button in Page
The situation is next: I have php file, which parses a web-page. on that
This is the situation: I have an ASP.NET MVC 4 application. When I run
On this site I have a situation where a user might need to be
I am in a real tricky situation where I have a page that allows
Trying my hand with jQuery. I have this strange situation that i wish to
I have a fairly standard situation: Click a button, it loads a transition page
Alright. This is the situation. I have created a website with a black banner
UPDATE** This is probably too much code. But... heres the situation. I have a
I have a unique situation over here. I have a button on a form

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.