File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes expanding a Struts app. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "expanding a Struts app." Watch "expanding a Struts app." New topic

expanding a Struts app.

Matt Sall

Joined: Jul 01, 2007
Posts: 19

I have a struts app that is partially taken from a book, it lets you search for name or a security number, it then return matches and present them in a JSP page. The names and numbers are taken from a DB. I now would like to add the functionality to add user to the DB.
I have the following files:



This is very basic, but I don't really know where to begin. What files should I add to keep it accordingly to MVC? Should I still have one controller, one model? I need a jump start here, thanks. Please tell if you need to see source.

Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

I guess you would need a view to display a add user jsp, 1 controller for the action and 1-2 model depending on how you design

===Vyas Sanzgiri===
My Blog
Matt Sall

Joined: Jul 01, 2007
Posts: 19
Can you have two controllers? My corrent looks like this:
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public final class SearchAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {

EmployeeSearchService service = new EmployeeSearchService();
ArrayList results;
SearchForm searchForm = (SearchForm) form;

//Perform employee search based on the criteria entered.
String name = searchForm.getName();
if (name != null && name.trim().length() > 0) {
results = service.searchByName(name);
} else {
results = service.searchBySsNum(searchForm.getSsNum().trim());
//Place search results in SearchForm for access by JSP.

//Forward control to this Action's input page.
return mapping.getInputForward();

I agree. Here's the link:
subject: expanding a Struts app.
It's not a secret anymore!