• 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

execute() method is not getting called when i pass ServletRequest and ServletResponse parameters

 
Ranch Hand
Posts: 77
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends , I started working on struts 1.3. My Action class execute() method is not being called when I write code like this ,but the constructor is getting called.

public class ActionOne extends Action {

public ActionOne(){
System.out.println("ActionOne object is created");
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
ServletRequest request, ServletResponse response) throws Exception {

System.out.println("execute method");
ActionForward af = mapping.findForward("one");
return af;
}

But when i change 3rd and 4th parameters of execute() method to (HttpServletRequest request, HttpServletResponse response ) it is working fine. My question is ,interfaces ServletRequest & ServletResponse method can hold sub types objects right , but why it dint work before and why is it working only when i use HttpServletRequest & HttpServletResponse ?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shiva,
Welcome to CodeRanch!

In Java, a method only overrides another if the method signature matches. In Struts 1, the method signature in Action is



You can verify this by adding the @Override annotation before the method and confirming it still compiles. The method you have with ServletRequest and ServletResponse does not override Struts' version. Again, you can verify this by adding the @Override annotation and seeing the code doesn't compile.

Since your method does not override the Struts one, Struts calls the default implementation in Action that doesn't do anything.
 
Shiva Gajjala
Ranch Hand
Posts: 77
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot for the reply. Actually I used eclipse and overridden the method execute() and I got the @Override annotation withit (later I removed the annotation though). I just checked Action class,it contains both the methods.

ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic.

ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response)
Process the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic.

Thats is the reason I was confused . Anyway I got the solution . ServletRequest, ServletResponse in execute() method is used for non-HTTP requests ,cannot be used for HTTP request.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic