• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

action class not being called.

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Debug breakpoints.
 
Ranch Hand
Posts: 948
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic