aspose file tools*
The moose likes Struts and the fly likes How to call an Action from Html link Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to call an Action from Html link " Watch "How to call an Action from Html link " New topic
Author

How to call an Action from Html link

Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
Hi

In one of my application I have to use <a>tag of html to call an action.In the href if i call my .do it is not working .Usually we call in the form action , but if i have to call through image or link like this.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Are you trying to post some form data with the link or just hit an action that doesn't care about form values?


A good workman is known by his tools.
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
Hello Archana,

I don't know whether my concept is right or wrong, but through a common html link <a href .....> you cannot activate an action. To activate a struts action through a link, struts provides its own link tag and I hope you must know about it. Its <html:link>. try to read a little bit detail about it in struts-documentation. I am providing a small example about activating an action through <html:link> tag.

Suppose your struts-config.xml file has entries like below.


<global-forwards>
<forward name="home" path="/index.do" />
</global-forwards>

<action-mappings>
<action path="/index"
type="mylib.IndexAction">
<forward name="success" path="/homepage.jsp" />
</action>
</action-mappings>


Now suppose in your page1.jsp has an entry like...


<html:link forward="home">Click Here For Homepage</html:link>


Now what it tells, when in your page1.jsp page you will click on that link, it'll search your struts-config.xml file for a forward with name home. And in your struts-config file you have actually activated once action index.do for this forward name. Right ?? Now ultimately you'll be forwarded to homepage.jsp page. If you'll view the source of that page1.jsp then, you'll find that above link statement is converted to <a href="/homepage.jsp">Click Here For Homepage</a>.


Regards<br />--<br />Niranjan Nanda<br />Consultant<br />Capgemini Consulting India <br />Mumbai<br />Phone: 9324951476
Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
Thanks for the detailed explanation.I applied that for my program ,it is working.

I really appreciate the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call an Action from Html link
 
Similar Threads
pass parameter action to action
Ajax - Struts - JSP
Struts Forward
struts 2: how to call action from href link
Cannot find bean in any scope