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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:25:09+00:00 2026-06-14T13:25:09+00:00

I rewrite application from servlets to Struts 2. Previously to get parameter value I

  • 0

I rewrite application from servlets to Struts 2.

Previously to get parameter value I could write:

request.getParameter("name");

Now I should do:

public class MyAction implements ParameterAware {
  private Map<String, String[]> parameters;

  @Override
  public void setParameters(Map<String, String[]> parameters) {
    this.parameters = parameters;
  }

  public String getParameterValue(String name){
    return parameters.get(name)[0];
  }

  // get this parameter

It was much easier when I used servlets!

To make code DRYer I can create class CustomActionSupport extending ActionSupport and put this code there. But why Struts doesn’t do it for me? How can I make my life easier?

I use ParameterAware as documentation says that it’s a preferred way.

  • 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-14T13:25:10+00:00Added an answer on June 14, 2026 at 1:25 pm

    The normal use case for Struts2 is to have action properties that correspond to parameters, and let the parameters interceptor set these for you before the action is executed.

    Struts2 is trying to hide the fact that your action is invoked as the result of an HTTP request. Trying to work directly with parameters is fighting that paradigm.


    Here’s a small example relying on the parameters interceptor. First, define a value object.

    public class Name {
    
      private String firstName;
      private String surname;
    
      public void setFirstName(String s) {
        this.firstName = s;
      }
    
      public void setSurname(String s) {
        this.surname = s;
      }
    
      /* Some interesting operations on Name... */
    
    }
    

    Define your Struts2 action to use Name. The properties of name will be set with HTTP parameters before execute() is called.

    public class NameAction extends Action {
    
      private final Name name = new Name();
    
      public Name getName() {
        return name;
      }
    
      public String execute() {
        /* Use "name" to do something interesting; its properties are set. */
      }
    
    }
    

    Now create a form that uses your action:

    <s:form action="name">
      <s:textfield name="name.firstName" label="First name" />
      <s:textfield name="name.surname" label="Last name" />
      <s:submit/>
    </s:form>
    

    Now the parameters will be set on your Name object when the form is submitted to the NameAction.

    You can set up the framework to do a lot more, such as validating parameters, using a IoC container to inject your action with objects, etc.

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

Sidebar

Related Questions

I am having to rewrite an application from C++ to C. I am using
I'am trying to rewrite zend framework configuration file from application.ini to application.yml format and
I would like to rewrite the URL of one of my pages from http://www.mydomain.com/some/application/page.html
I'm using the cakePHP email component for sending mails from my application. Now the
I rewrite application from ASP.NET to Silverlight and use NHibernate 2. Tables in my
I have to rewrite a large database application, running on 32 servers. The hardware
I have a custom HttpModule rewrite engine in an existing web application project that
Can the IIS7 URL Rewrite Module be bin deployed with an ASP.net application? Or
I want to output some characters in C# console application and then rewrite them,
This might not be possible but before I rewrite part of my application I

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.