0

I have an index.jsp and I want to add a link in it such that when I click on the link I should be navigated to an action class info.action.

In this action class I am using a service manager instance, calling the service and from this service accessing the Data Access Object (DAO). The result fetched from DAO has some check condition in service and according to same it should display another jsp called result.jsp.

How do I call an action from index.jsp through a link?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203

1 Answers1

0

The URL should match action servlet mapping url-pattern in web.xml, which will invoke the action servlet, and should contain the path attribute value of the action mapping for that action, which will help action servlet to find the action mapping for your action class.

e.g. if in your web.xml, the mapping for the action servlet is as follows -

<servlet-mapping>
    <servlet-name>action-servlet</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

and in you struts-config.xml, the mapping for the action is as follows -

<action-mappings>
    <action path="/amyaction" ...
    ...

Then something like http://host:port/myapp/myaction.do should invoke the action.

You can refer to this - https://stackoverflow.com/a/1388120/738746 on how to display the link using <html:link (struts tag) and <c:url (JSTL tag).

Community
  • 1
  • 1
Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142