• 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

Struts Action and Java Servlet

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am using struts framework..all of a sudden it seems i miss the part of the servlet. because org.apache.struts.action.Action class seems to take the position of Servlet. If it is not correct, How to use Servlets in struts application. In which scenario i should go for the Servlets usage in Struts.


Thanks,
 
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
It's a rare occasion you'd want to use a servlet in a Struts app, and rarer still you'd *need* to.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In your web.xml, you would have defined something like this to handle all struts requests:

<servlet-mapping>
<servletName> ActionServlet </servletName>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


To access a servlet, you need to define a servlet mapping with different name like this:

<servlet-mapping>
<servletName> MyServlet </servletName>
<url-pattern>/servlet/MyServlet</url-pattern>
</servlet-mapping>

Now all requests to /servlet/MyServlet/ will go to new servlet.

In scenarios where you want to send an Ajax call, you can use servlet.

Regards
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chetan agg wrote:In scenarios where you want to send an Ajax call, you can use servlet.


NOT necessary, you can handle AJAX calls with Struts action too.

Also, think from the "Controller" prospective, you'll just miss all the functionality provided by the Struts Controller. like action mapping, dispatch action, etc, One more, when you use the Servlets, you have to edit the "web.xml" for the servelet mapping entry, which is, not considered a good practice if you're uisng struts for not-so-special actions, like AJAX. Place all the action mapping in struts-config.xml

So you rarely need servelets in Struts, and that's why Strusts1 is designed to enhance servelets use..
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have to tell you that i am not good at J2EE, so you are taking about AJAX calls to servlet. I even confuse how to use servlets then how can i use AJAX in struts. If you can help your point through an example code, i might understand.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AJAX is used with JavaScript for the asynchronous request to the server and Servlet is one of the request processor.

For more about AJAX OR Google.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic