permaculture playing cards*
The moose likes Struts and the fly likes action class not being called. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "action class not being called." Watch "action class not being called." New topic
Author

action class not being called.

lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
Hi all,
this there a way to check if my actionclass is being call. I tried to put the Systm.out.println. but nothing is display so i assumed my action is not being call.

Im using Struts 1.3.5

Action Class:
private final static String SUCCESS = "success";
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception{
System.out.println("action");
ContentForm cfrm = (ContentForm) form;
Session session = null;
System.out.println(cfrm.getContent());

try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Content content = new Content();
content.setContent(cfrm.getContent());
content.setName(cfrm.getName());
content.setFile(cfrm.getFile());
content.setTitle(cfrm.getTitle());
session.save(content);
System.out.println("Done");
}catch (Exception e)
{
System.err.print(e.getStackTrace());
}
return mapping.findForward(SUCCESS);
}

struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<!--
This is a blank Struts configuration file with an example
welcome action/page and other commented sample elements.

Struts Validator is configured using the factory defaults
and is ready-to-use.

NOTE: If you have a generator tool to create the corresponding Java classes
for you, you could include the details in the "form-bean" declarations.
Otherwise, you would only define the "form-bean" element itself, with the
corresponding "name" and "type" attributes, as shown here.
-->


<struts-config>
<form-beans>
<form-bean name="contentForm"
type="com.strutsexample.form.ContentForm"/>
</form-beans>

<action-mappings>
<action path="/list"
name="contentForm"
scope="request"
parameter="method"
type="com.strutsexample.action.ContentAction">
<forward name="success" path="/list.jsp"/>
</action>
<action path="/insert" forward="/insert.jsp"/>
<action path="/listAdd"
name="contentForm"
scope="request"
input="/insert.jsp"
parameter="method"
type="com.strutsexample.action.ContentAction">
<forward name="success" path="/list.jsp"/>
</action>
</action-mappings>
<message-resources parameter="com.strutsexample.message" null="false"/>
</struts-config>

JSP page:
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>



<html:form action="/listAdd" method="get">
<table>
<tr><td><bean:message key="label.name"/></td><td><html:text property="name"/></td></tr>
<tr><td><bean:message key="label.title"/></td><td><html:text property="title"/></td></tr>
<tr><td><bean:message key="label.content"/></td><td><html:textarea property="content"/></textarea></td></tr>
<tr><td><bean:message key="label.file"/></td><td><html:file property="file"/></td></tr>
<tr><td> <html:hidden property="method" value="insert" />
<html:submit value="submit"></html:submit></td><td></td></tr>
</table>
</html:form>
Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
Debug breakpoints.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
So what behavior are you seeing? Note that the default value for the validate property of an action mapping is "true". It could be the case that validation is failing in which case the action class is never called.

- Brent
Suresh Kumar Ramasamy
Greenhorn

Joined: Mar 18, 2008
Posts: 7
Brent Sterling wrote:So what behavior are you seeing? Note that the default value for the validate property of an action mapping is "true". It could be the case that validation is failing in which case the action class is never called.

- Brent


I know it is a 5 year old thread, but I am not able to resist posting Thanks. I spent almost a day debugging and only after reading your tip my problem got solved. Thank You.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: action class not being called.
 
Similar Threads
Problems with firsttruts Application
Struts Exception
Struts validation not working
Problems with first Struts Application - please help...
server encountered an internal error ;while running application