Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call an Action from Html link

 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to post some form data with the link or just hit an action that doesn't care about form values?
 
N Nanda
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the detailed explanation.I applied that for my program ,it is working.

I really appreciate the help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic