public class UserAction extends DispatchAction
{
//Performs The SearchUser Action When the user submits the form and clicks the SearchUser button
public ActionForward SearchUser(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception
{
UserSearchService service = new UserSearchService();
ArrayList<
String> results = null;
UserForm userForm = (UserForm) form;
String name = userForm.getFname();
if(name != null & name.trim().length()>0)
results = service.search(name);
if(results.size()< 1)
{
System.out.println(results.size());
throw new NoResultsFoundException();
}
userForm.setResults(results);
return new ActionForward("/user.jsp");
}
//Performs The ListUser Action When the user clicks the ListUsers link
public ActionForward ListUser(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
{
UserForm userForm = (UserForm) form;
Connection con= null;
Statement stmt = null;
ResultSet rs = null;
ArrayList<String> result = new ArrayList<String>();
try
{
con = ConMgmt.getConnection();
System.out.println("success");
stmt = con.createStatement();
rs = stmt.executeQuery("select * from puser");
while(rs.next())
{
String fname = rs.getString(1);
String lname = rs.getString(2);
result.add(fname);
result.add(lname);
}
userForm.setResults(result);
} catch (SQLException e) {
e.printStackTrace();
}
return new ActionForward("/user.jsp");
}
}