Questions Pass values from html to Action Class Struts
Krupa Asked

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.

Comments :

Krupa remember to always, always, always indent the code.

Not sure what you're asking; why not just a form? Otherwise you can build the href using the flagvalue on JSP render, or via JS.


3 Answers :
Reenu answered

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>
Mack replied
can you write the action class code snippet . So its makes helpful.;
Rish answered

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>
Satya answered

Simply,

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

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