posted 19 years ago
Hello Manish.. Try this simple example and I hope it'll help you.
Suppose you have a business logic component BooksDAO which has few methods like getAllBooks(...) and addBook(...) etc. Now in a view (say)books.jsp you hav links like View All Books, Add A Book, etc..
You can build those links like...
<html:link href="/manageBooks.do?page=view">View All Books</html:link>
Now write the following Action class ManageBooks.java
package pack1;
// imports
public class ManageBooks extends DispatchAction implements java.io.Serializable
{
public ActionForward view(ActionMapping mapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
//Call the business logic getAllBooks() here
return mapping.findForward("view");
}
// Similarly we can put another method say add
public ActionForward add(ActionMapping mapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
//Call the business logic addBook() here
return mapping.findForward("add");
}
}// End of class
--------------
Now in your struts-config.xml file write the following to invoke the dispatch actions
<action path="/manageBooks" type="pack1.ManageBooks"
scope="request" validate="false" parameter="page" input="books.jsp">
<forward name="view" path="/viewBooks.jsp" redirect="true"/>
<forward name="add" path="/addBooks.jsp" redirect="true"/>
</action>
Now in above action, the parameter attribute is important as according to it, the methods in the disptch action classes will be deligated.
regards,
Niranjan