Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Action and Java Servlet

 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • 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,
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
chetan agg
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic