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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:20:38+00:00 2026-06-14T05:20:38+00:00

I have a form in a jsp. There are two submit buttons: Search and

  • 0

I have a form in a jsp. There are two submit buttons: “Search” and “Add New” button.

<s:form name="searchForm" action="employeeAction" method="post">
    <s:textfield name="id" label="Employee ID"/>
    <s:textfield name="name" label="Employee Name"/>

    <s:submit value="Search"/>
    <s:submit value="Add New"/>
</s:form>

In struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

        <default-action-ref name="index" />

        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>

    </package>

    <package name="example" namespace="/example" extends="default">

        <action name="employeeAction" class="example.EmployeeAction">
           <result name="search">/example/search.jsp</result>
           <result name="add" type="redirect">/example/add.jsp</result>
        </action>

    </package>
</struts>

In Struts Action class, we know that there is only one method that processing http request, that is execute() method.

In my expected case, when I clicked Search button, it will perform searching data and render data to /example/search.jsp, when I clicked Add New button, it will perform redirecting page to /example/add.jsp. However, both buttons when clicked will go into execute() method. So I need to know how to detect which button clicked in the execute() method.

The scenario looks like this

public class EmployeeAction extends ActionSupport {

    public String execute() throws Exception {

        //PSEUDOCODE
        //IF (submitButton is searchButton) 
        //    return doSearch();
        //ELSE IF (submitButton is addNewButton) 
        //    return doAddNew();

        return SUCCESS;
    }

    public String doSearch() throws Exception {
        //perform search logic here
        return "search";
    }

    public String doAddNew() throws Exception {
        return "add";
    }
}
  • 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-14T05:20:39+00:00Added an answer on June 14, 2026 at 5:20 am

    You can define two actions in struts.xml file and use action attribute of <s:submit> tag in order to submit to different actions http://struts.apache.org/docs/submit.html.

    In JSP:

    <s:submit value="Search" action="searchEmployeeAction"/>
    <s:submit value="Add New" action="addEmployeeAction"/>
    

    In struts.xml:

    <action name="addEmployeeAction" method="add" class="example.EmployeeAction">
        <result>/example/add.jsp</result>
    </action>
    
    <action name="searchEmployeeAction" method="search" class="example.EmployeeAction">
        <result>/example/search.jsp</result>
    </action>
    

    And in your action create two public String methods add and search.

    Read about Multiple Submit Buttons http://struts.apache.org/docs/multiple-submit-buttons.html.

    Update

    Starting from Struts2 version 2.3.15.3 you need to set struts.mapper.action.prefix.enabled constant to true in order to enable support for action: prefix.

    Put that in your struts.xml file:

    <constant name="struts.mapper.action.prefix.enabled" value="true" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jsp with a submit based on the html:form action. <html:form action=/nextPath>
I have the following code: index.jsp: <form name=f action=db/ajoutConducteur.jsp method=post> <input type=text pattern=\d{8} required
I have a form made in JSP, here I have multiple buttons - Approve,
I have the following form in a Struts2 JSP that contains some radio buttons.
I have the following in jsp: <form action=/ucReady2/uploadservlet method=post enctype=multipart/form-data> <label for=filename_1>File: </label> <input
I have a view Search.jsp that has a form:form that is connected to a
I have two objects: Form . A form that I populate from a JSP
I have a JSP page in which there is a hyperlink to add a
I have two jsp pages. one.jsp and two.jsp . On one.jsp there is a
I have a jsp which contains a html form. Inside it there is an

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.