• 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

Is there any way to call servlet?

 
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sorry for asking this stupid question.
Is there any way to call a servlet dynamically on start up of applcation (Not running that servlet)
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Invocation of a Servlet requires to have a request object and a response object. Since the event of starting the application has nothing to do with a request or response, there isn't a proper way to call a Servlet. If you need some code to be executed at the application startup, you can setup a context listener.
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet can be invoked using HTTPRequest and HTTPResponse objects. As Devaka mentioned, this is the only way to call Servlet.

If you want Container to run your servlet at start up of application, try exploring <load-on-startup> element of web.xml. With this, you can load servlet at the start of application.

Please let us know the purpose with which you want to call Servlet dynamically on start up of applcation (Not running that servlet).

Do you want to setup some variable, call some generic method to iniatilize DB connection etc?

Please tell us your reason. We may find some other way to achieve your requirement.

~ abhay
 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhay Agarwal wrote:If you want Container to run your servlet at start up of application, try exploring <load-on-startup> element of web.xml. With this, you can load servlet at the start of application.


Just for not to make the OP confused: <load-on-startup> does nothing other than instantiating the servlet and calling the init() method. In other words, neither doGet or doPost is called by that.
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application which execute applet and it displays a window in swings and in parallel to applet i have to execute servlet to communicate with server for fetching data for swings.
 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that an Applet is an application that runs at the client end. If you need to send something from your Applet to a web server, you can do that by sending a typical HTTP request. If you have a problem in doing so, please start a new topic in our Applets forum.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The applet has to call a server to get the data for the Swing model. If the server is a web server using servlets, the servlet will be automatically started when the first request comes in.

You can specify load-on-startup in the web.xml file to cause the servlet to be loaded when the webapp first starts up, and that will save a little time when the first servlet request is made, but other than that, the results will be the same as the default on-demand servlet startup. Once the servlet has started, it remains available until the webapp is shut down.

Note that I said "available", not "running". That's because servlets are not programs, and they don't "run". They don't have their own private execution threads. A servlet is more like a DLL than an executable in that respect, if you prefer to think of it in Microsoft Windows terms.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic