aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "expanding a Struts app." Watch "expanding a Struts app." New topic
Author

expanding a Struts app.

Matt Sall
Greenhorn

Joined: Jul 01, 2007
Posts: 19
Hi,

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:
Model:
Employee.java
EmployeeSearchService.java

Controller:
SearchAction.java

View:
SearchForm.java
index.jsp
search.jsp

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.

/Matt
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
Greenhorn

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.
searchForm.setResults(results);

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

/Matt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: expanding a Struts app.
 
Similar Threads
so, we don't need to code any "ActionServlet" in our app ?
JSP MVC JDBC
JTable Question
Connection Pooling and JSTL
JAR the web-application or use WSDL/SOA ?!?!