File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

How to call an Action from Html link

Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147

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

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.

<forward name="home" path="/" />

<action path="/index"
<forward name="success" path="/homepage.jsp" />

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 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:
subject: How to call an Action from Html link
It's not a secret anymore!