• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

problem with action mapping

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags and disable HTML when posting code.

Is there anything in the logs/console? Are you really using Struts 1.0?! Even 1.1 seems a bit... old.
 
abheeshek reddy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Please use code tags and disable HTML when posting code.

Is there anything in the logs/console? Are you really using Struts 1.0?! Even 1.1 seems a bit... old.





Thanks for Suggestion David.

Sure i will follow it when post next time.

There are no Exceptions and errors in either console or logs :banghead: :banghead:
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that your properties file is not on the classpath. Place the file with your source code and recompile.....

Cheers!
Sid
 
abheeshek reddy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sidd Kulk wrote:I believe that your properties file is not on the classpath. Place the file with your source code and recompile.....

Cheers!
Sid





properties file is in classpath.
assuming if properties file is not class path <bean:message tag should not work but its working fine.

I am not able to understand the relation between action and properties file.


Thanks
abhee>
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic