• 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

Program Exit

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having some trouble in my program just before I exit when I use the System.exit(0) command.All I have to do is exit from the main program after checking some basic conditions(if/else statements) and not to proceed further processing.But although it exits at that point it brings down with it my servlet engine which I do not want.I tried using try/catch to remedy the situation.But my main question is why is it bringing down my servlet engine to a halt if I use that command because that was how we usually exit from a point in the program in other languages like C++.Please do provide any suggestions as to why it is happening.
Thanking You
Ashwin
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.exit() is a command that stops the entire JVM - of course it stops the servlet engine. Exactly what are you trying to do?
If you are talking about a servlet - all you have to do is return from the service or doPost or doGet method. The way a servlet is run inside a servlet engine is similar to the way an applet is run inside a browser.
Programming a servlet or JSP is NOT like programming a stand-alone application - there are many adjustments you have to make in programming style.
Bill

------------------
author of:
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William,
Thank you for your valuable response.I came to know that System.exit(n) stops the JVM, i.e it stops the child process but it returns the status code to the parent process(denoting success for 0 and failure for n>0).All I am trying to do is to exit from the servlet code after checking for some conditions by hard coding instead of the system raising any SQL exceptions(like when I do a delete with no parameters passed) because they cannot be caught by an ordinary java client(run from the command prompt talking to a sevlet).I succeded in in solving the problem if I use try catch statements but I thought if there was a way in Java to exit from a program as in C++ using exit command.Could you tell me if there was any other way that we could solve this problem.
Thanking you,
Ashwin
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic