Pass values from html to Action Class Struts

I am completely new to Struts and now I am facing some issues.

Here is my html code :-

<div id = "processingMode">
   <div id = "appButton">
      <input type="hidden" value="Cancel" name="flagValue" />
      <a href="**action Class path**">Cancel</a>
   </div>
</div>

And I want to retrieve hidden field values in the action class (or please let me know how to pass values from html to action class).

Can anyone help me to achieve this.

Answers


In order to pass the hidden parameter value using struts you first need to add the struts library and import the struts tag library Try this below code

<s:url action="actionclass">
    <s:param name="id" value="parametervalue" />
</s:url>

Hi Krupa

To send hidden parameters from view page to action class, you have to use <s:hidden></s:hidden> struts tag. You can pass the parameters through the URL too. But that is not a best practice to do so when it comes to security.

so try to use struts tag to achieve desired task. find the following sample app code to get a better understanding :-

View Page

<s:form action="testAction">
   <s:hidden name="EmpName" value="DummyName" />
   <s:submit value="Submit" />
</s:form>

Action class

public class Employee extends ActionSupport {
   private String EmpName;

   // getters and setters

   public String execute() {
      System.out.println("Employee Name  :- "+this.getEmpName());
      return "success";
   }
}

struts.xml

<action name="testAction" class="Employee">
   <result name="success"><path of your view page></result>
</action>

Simply,

<a href="actionname.do?q=somevalue">Cancel</a>

In Action class, create a parameter q and its set and get methods


Need Your Help

Delphi Gecko SDK - did anyone succeeded with that + XULRunner 1.9?

delphi delphi-7 gecko xulrunner geckosdk

I did a checkout of d-gecko SDK from sf.net ( http://sourceforge.net/projects/d-gecko/ ).

JavaScript - Submit Form with localtime

javascript html forms date time

I'm trying to combine Submit form and date/localtime