Problem: Control is not going to Action
I am able to see only blank page after clicking on Search for Employees
Here is my welcome.jsp
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html locale="true">
<head>
<title><bean:message key="welcome.title"/></title>
<html:base/>
</head>
<body bgcolor="white">
<html:link forward="searchlink">Search for Employees</html:link>
<logic:notPresent name="org.apache.struts.action.MESSAGE" scope="application">
ERROR: Application resources not loaded -- check servlet container
logs for error messages.
</logic:notPresent>
<h3><bean:message key="welcome.heading"/></h3>
<bean:message key="welcome.message"/>
</body>
</html:html>
Here is my action
public class SearchAction extends Action{
public ActionForward execute(
ActionForm form,
ActionMapping mapping,
HttpServletRequest request,
HttpServletResponse response){
SearchForm sForm =(SearchForm)form;
System.out.println("inside aciton class");
EmployeeSearchService service = new EmployeeSearchService();
ArrayList results = new ArrayList();
System.out.println("inside action class");
if(sForm.getName()!=null || sForm.getSsNum()!=null){
System.out.println("inside action class and if block");
String name=sForm.getName();
System.out.println("inside action class value of name "+name);
String ssNum=sForm.getSsNum();
System.out.println("inside action class value of ssNum "+ssNum);
if(name!=null && name.trim().length()>0){
results = service.searchByName(name);
} else{
results = service.searchBySsNum(ssNum);
}
sForm.setResults(results);
}
return mapping.findForward("success");
}
}
Here is my Form
package com.jamesholmes.struts;
import java.util.List;
import org.apache.struts.action.ActionForm;
public class SearchForm extends ActionForm{
private String name;
private String ssNum;
private List results;
public SearchForm(){
System.out.println("inside SearchForm");
}
public List getResults() {
return results;
}
public void setResults(List results) {
this.results = results;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSsNum() {
return ssNum;
}
public void setSsNum(String ssNum) {
this.ssNum = ssNum;
}
}
Here is my Struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD
Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- ==================================== Data Source Configuration -->
<!--
<data-sources>
<data-source>
<set-property
property="autoCommit"
value="false"/>
<set-property
property="description"
value="Example Data Source Configuration"/>
<set-property
property="driverClass"
value="org.postgresql.Driver"/>
<set-property
property="maxCount"
value="4"/>
<set-property
property="minCount"
value="2"/>
<set-property
property="password"
value="mypassword"/>
<set-property
property="url"
value="jdbc:postgresql://localhost/mydatabase"/>
<set-property
property="user"
value="myusername"/>
</data-source>
</data-sources>
-->
<!-- ======================================== Form Bean Definitions -->
<form-beans>
<form-bean name="searchForm" type="com.jamesholmes.struts.SearchForm"/>
</form-beans>
<!-- ================================= Global Exception Definitions -->
<global-exceptions>
</global-exceptions>
<!-- =================================== Global Forward Definitions -->
<global-forwards>
<!-- Default forward to "Welcome" action -->
<!-- Demonstrates using index.jsp to forward -->
<forward
name="searchlink"
path="/pages/Search.jsp"/>
<forward
name="welcome"
path="/Welcome.do"/>
</global-forwards>
<!-- =================================== Action Mapping Definitions -->
<action-mappings>
<!-- Default "Welcome" action -->
<!-- Forwards to Welcome.jsp SearchLink-->
<action
path="/Welcome"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/Welcome.jsp"/>
<action path="/HrAction"
name="searchForm"
type="com.jamesholmes.struts.SearchAction"
scope="request">
<forward name="success" path="/pages/Search.jsp"/>
</action>
</action-mappings>
<!-- ===================================== Controller Configuration -->
<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<!-- ================================ Message Resources Definitions -->
<message-resources parameter="application"/>
<!-- ======================================= Plug Ins Configuration -->
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-parser-validate" value="true" />
</plug-in>
<!-- end comment if struts1.0.x -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
here is my Search.jsp
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html:html>
<head>
<title> Mini HR Portal</title>
</head>
<BODY>
OFS, Inc. Mini Human Resources Portal
<html:errors/>
<html:form action="/HrAction">
<table>
<tr>
<td ><bean:message key="search.Name"/>:</td>
<td><html:text property="name"/></td>
</tr>
<tr>
<td></td>
<td>--or--</td>
</tr>
<tr>
<td ><bean:message key="serach.ssNum"/>:</td>
<td><html:text property="ssNum"/> (XXX-XX-XXX)</td>
</tr>
<tr>
<td></td>
<td><html:submit/></td>
</tr>
</table>
</html:form>
<logic:present name="searchForm" property="results">
<bean:size id="size" name="searchForm" property="results"/>
<logic:equal name="size" value="0">
<center>
No Emplyoees found</center>
</logic:equal>
<logic:greaterThan name="size" value="0">
<table border="1">
<tr>
<th>Name</th>
<th>Social Security Number</th>
</tr>
<logic:iterate id="result" name="searchForm" property="results">
<tr>
<td><bean:write name="result" property="name"/></td>
<td><bean:write name="result" property="ssNum"/></td>
</tr>
</logic:iterate>
</table>
</logic:greaterThan>
</logic:present>
</html:html>