Sort
Profile photo for Deo Rajeev Tripathi

destroy() gets executed and the initialization process continues. Servlet will not be destroyed.

For more Info check out below link :

What happens if you call destroy() from init() in java servlet?

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of th

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of the biggest mistakes and easiest ones to fix.

Overpaying on car insurance

You’ve heard it a million times before, but the average American family still overspends by $417/year on car insurance.

If you’ve been with the same insurer for years, chances are you are one of them.

Pull up Coverage.com, a free site that will compare prices for you, answer the questions on the page, and it will show you how much you could be saving.

That’s it. You’ll likely be saving a bunch of money. Here’s a link to give it a try.

Consistently being in debt

If you’ve got $10K+ in debt (credit cards…medical bills…anything really) you could use a debt relief program and potentially reduce by over 20%.

Here’s how to see if you qualify:

Head over to this Debt Relief comparison website here, then simply answer the questions to see if you qualify.

It’s as simple as that. You’ll likely end up paying less than you owed before and you could be debt free in as little as 2 years.

Missing out on free money to invest

It’s no secret that millionaires love investing, but for the rest of us, it can seem out of reach.

Times have changed. There are a number of investing platforms that will give you a bonus to open an account and get started. All you have to do is open the account and invest at least $25, and you could get up to $1000 in bonus.

Pretty sweet deal right? Here is a link to some of the best options.

Having bad credit

A low credit score can come back to bite you in so many ways in the future.

From that next rental application to getting approved for any type of loan or credit card, if you have a bad history with credit, the good news is you can fix it.

Head over to BankRate.com and answer a few questions to see if you qualify. It only takes a few minutes and could save you from a major upset down the line.

How to get started

Hope this helps! Here are the links to get started:

Have a separate savings account
Stop overpaying for car insurance
Finally get out of debt
Start investing with a free bonus
Fix your credit

Profile photo for Agn Hub

Hiii friends,

Before knowing servlet container you have to know about web container .

So i am going to demonstrate you all this :-

1. What is a Web Server?

To know what is a Servlet container, we need to know what is a Web Server first

A web server uses HTTP protocol to transfer data.So what the server does is sending a web page to the client. The transformation is in HTTP protocol which specifies the format of request and response message.

2. What is a Servlet Container?

As we see here, the user/client can only request static webpage from the server. This is not good enough, if the user wants to rea

Hiii friends,

Before knowing servlet container you have to know about web container .

So i am going to demonstrate you all this :-

1. What is a Web Server?

To know what is a Servlet container, we need to know what is a Web Server first

A web server uses HTTP protocol to transfer data.So what the server does is sending a web page to the client. The transformation is in HTTP protocol which specifies the format of request and response message.

2. What is a Servlet Container?

As we see here, the user/client can only request static webpage from the server. This is not good enough, if the user wants to read the web page based on his input. The basic idea of Servlet container is using Java to dynamically generate the web page on the server side. So servlet container is essentially a part of a web server that interacts with the servlets.

Servlet container is the container for Servlets.

3. What is a Servlet?

Servlet is an interface defined in javax.servlet package. It declares three essential methods for the life cycle of a servlet – init(), service(), and destroy(). They are implemented by every servlet(defined in SDK or self-defined) and are invoked at specific times by the server.

  1. The init() method is invoked during initialization stage of the servlet life cycle. It is passed an object implementing the javax.servlet.ServletConfig interface, which allows the servlet to access initialization parameters from the web application.
  2. The service() method is invoked upon each request after its initialization. Each request is serviced in its own separate thread. The web container calls the service() method of the servlet for every request. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request.
  3. The destroy() method is invoked when the servlet object should be destroyed. It releases the resources being held.

From the life cycle of a servlet object, we can see that servlet classes are loaded to container by class loader dynamically. Each request is in its own thread, and a servlet object can serve multiple threads at the same time(thread not safe). When it is no longer being used, it should be garbage collected by JVM.

Like any Java program, the servlet runs within a JVM. To handle the complexity of HTTP requests, the servlet container comes in. The servlet container is responsible for servlets’ creation, execution and destruction.

4. How Servlet container and web server process a request?

  1. Web server receives HTTP request
  2. Web server forwards the request to servlet container
  3. The servlet is dynamically retrieved and loaded into the address space of the container, if it is not in the container.
  4. The container invokes the init() method of the servlet for initialization(invoked once when the servlet is loaded first time)
  5. The container invokes the service() method of the servlet to process the HTTP request, i.e., read data in the request and formulate a response. The servlet remains in the container’s address space and can process other HTTP requests.
  6. Web server return the dynamically generated results to the correct location

The six steps are marked on the following diagram:

5. The role of JVM

Using servlets allows the JVM to handle each request within a separate Java thread, and this is one of the key advantage of Servlet container. Each servlet is a Java class with special elements responding to HTTP requests. The main function of Servlet contain is to forward requests to correct servlet for processing, and return the dynamically generated results to the correct location after the JVM has processed them. In most cases servlet container runs in a single JVM, but there are solutions when container need multiple JVMs

Thanks

I think have also covered all the related topics.

Profile photo for Shaikh Hamid

For Example User Click on Logout Link To Perform Below Codes. See I apply comments how to destroy session object please read comments.

<a href="<%=request.getContextPath()%>/LogoutServlet">Logout</a>

Look LogoutServlet.java file

LogoutServet.java

public class LogoutServlet extends HttpServlet

{

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{

HttpSession session = request.getSession(false); //getting to session object

if(session!=null) // check if condition the session not null

{

session.invalidate(); //using this method to destroy the

For Example User Click on Logout Link To Perform Below Codes. See I apply comments how to destroy session object please read comments.

<a href="<%=request.getContextPath()%>/LogoutServlet">Logout</a>

Look LogoutServlet.java file

LogoutServet.java

public class LogoutServlet extends HttpServlet

{

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{

HttpSession session = request.getSession(false); //getting to session object

if(session!=null) // check if condition the session not null

{

session.invalidate(); //using this method to destroy the sesion object

request.setAttribute("errorMS", "Logged out successfully"); //send "errorMSG" object on client side. And get using request.getAttribute() method

RequestDispatcher requestDispatcher = request.getRequestDispatcher("login.jsp"); // using RequestDispatcher method forward to login page.

requestDispatcher.forward(request, response);

System.out.println("you can logged out successfully");

}

}

}

Profile photo for Razneekant Pardhan

Let me describe you with clear cut picture. with details of servlet life cycle.

  1. Servlet container have the full responsible for creating and destroying servlet class object.
  2. Servlet life cycle have 3 method init(servletconfig), service(-,-), and destroy()

One misconception : everyone think that destroy ( ) method destroys the servlet class object, But this is totaly wrong.

Destroy method does not destroy our servlet class object , Servlet container takes the responsibility to create and destroy the srervelet class object,

Destroy method is called for cleanup operation like closing the jdbc con

Let me describe you with clear cut picture. with details of servlet life cycle.

  1. Servlet container have the full responsible for creating and destroying servlet class object.
  2. Servlet life cycle have 3 method init(servletconfig), service(-,-), and destroy()

One misconception : everyone think that destroy ( ) method destroys the servlet class object, But this is totaly wrong.

Destroy method does not destroy our servlet class object , Servlet container takes the responsibility to create and destroy the srervelet class object,

Destroy method is called for cleanup operation like closing the jdbc connection just before the servlet object going to destroy. Destroy method is one time executing life cycle method.

Profile photo for Quora User

Here’s the thing: I wish I had known these money secrets sooner. They’ve helped so many people save hundreds, secure their family’s future, and grow their bank accounts—myself included.

And honestly? Putting them to use was way easier than I expected. I bet you can knock out at least three or four of these right now—yes, even from your phone.

Don’t wait like I did. Go ahead and start using these money secrets today!

1. Cancel Your Car Insurance

You might not even realize it, but your car insurance company is probably overcharging you. In fact, they’re kind of counting on you not noticing. Luckily,

Here’s the thing: I wish I had known these money secrets sooner. They’ve helped so many people save hundreds, secure their family’s future, and grow their bank accounts—myself included.

And honestly? Putting them to use was way easier than I expected. I bet you can knock out at least three or four of these right now—yes, even from your phone.

Don’t wait like I did. Go ahead and start using these money secrets today!

1. Cancel Your Car Insurance

You might not even realize it, but your car insurance company is probably overcharging you. In fact, they’re kind of counting on you not noticing. Luckily, this problem is easy to fix.

Don’t waste your time browsing insurance sites for a better deal. A company called Insurify shows you all your options at once — people who do this save up to $996 per year.

If you tell them a bit about yourself and your vehicle, they’ll send you personalized quotes so you can compare them and find the best one for you.

Tired of overpaying for car insurance? It takes just five minutes to compare your options with Insurify and see how much you could save on car insurance.

2. Ask This Company to Get a Big Chunk of Your Debt Forgiven

A company called National Debt Relief could convince your lenders to simply get rid of a big chunk of what you owe. No bankruptcy, no loans — you don’t even need to have good credit.

If you owe at least $10,000 in unsecured debt (credit card debt, personal loans, medical bills, etc.), National Debt Relief’s experts will build you a monthly payment plan. As your payments add up, they negotiate with your creditors to reduce the amount you owe. You then pay off the rest in a lump sum.

On average, you could become debt-free within 24 to 48 months. It takes less than a minute to sign up and see how much debt you could get rid of.

3. You Can Become a Real Estate Investor for as Little as $10

Take a look at some of the world’s wealthiest people. What do they have in common? Many invest in large private real estate deals. And here’s the thing: There’s no reason you can’t, too — for as little as $10.

An investment called the Fundrise Flagship Fund lets you get started in the world of real estate by giving you access to a low-cost, diversified portfolio of private real estate. The best part? You don’t have to be the landlord. The Flagship Fund does all the heavy lifting.

With an initial investment as low as $10, your money will be invested in the Fund, which already owns more than $1 billion worth of real estate around the country, from apartment complexes to the thriving housing rental market to larger last-mile e-commerce logistics centers.

Want to invest more? Many investors choose to invest $1,000 or more. This is a Fund that can fit any type of investor’s needs. Once invested, you can track your performance from your phone and watch as properties are acquired, improved, and operated. As properties generate cash flow, you could earn money through quarterly dividend payments. And over time, you could earn money off the potential appreciation of the properties.

So if you want to get started in the world of real-estate investing, it takes just a few minutes to sign up and create an account with the Fundrise Flagship Fund.

This is a paid advertisement. Carefully consider the investment objectives, risks, charges and expenses of the Fundrise Real Estate Fund before investing. This and other information can be found in the Fund’s prospectus. Read them carefully before investing.

4. Earn Up to $50 this Month By Answering Survey Questions About the News — It’s Anonymous

The news is a heated subject these days. It’s hard not to have an opinion on it.

Good news: A website called YouGov will pay you up to $50 or more this month just to answer survey questions about politics, the economy, and other hot news topics.

Plus, it’s totally anonymous, so no one will judge you for that hot take.

When you take a quick survey (some are less than three minutes), you’ll earn points you can exchange for up to $50 in cash or gift cards to places like Walmart and Amazon. Plus, Penny Hoarder readers will get an extra 500 points for registering and another 1,000 points after completing their first survey.

It takes just a few minutes to sign up and take your first survey, and you’ll receive your points immediately.

5. Get Up to $300 Just for Setting Up Direct Deposit With This Account

If you bank at a traditional brick-and-mortar bank, your money probably isn’t growing much (c’mon, 0.40% is basically nothing).

But there’s good news: With SoFi Checking and Savings (member FDIC), you stand to gain up to a hefty 3.80% APY on savings when you set up a direct deposit or have $5,000 or more in Qualifying Deposits and 0.50% APY on checking balances — savings APY is 10 times more than the national average.

Right now, a direct deposit of at least $1K not only sets you up for higher returns but also brings you closer to earning up to a $300 welcome bonus (terms apply).

You can easily deposit checks via your phone’s camera, transfer funds, and get customer service via chat or phone call. There are no account fees, no monthly fees and no overdraft fees. And your money is FDIC insured (up to $3M of additional FDIC insurance through the SoFi Insured Deposit Program).

It’s quick and easy to open an account with SoFi Checking and Savings (member FDIC) and watch your money grow faster than ever.

Read Disclaimer

5. Stop Paying Your Credit Card Company

If you have credit card debt, you know. The anxiety, the interest rates, the fear you’re never going to escape… but a website called AmONE wants to help.

If you owe your credit card companies $100,000 or less, AmONE will match you with a low-interest loan you can use to pay off every single one of your balances.

The benefit? You’ll be left with one bill to pay each month. And because personal loans have lower interest rates (AmONE rates start at 6.40% APR), you’ll get out of debt that much faster.

It takes less than a minute and just 10 questions to see what loans you qualify for.

6. Lock In Affordable Term Life Insurance in Minutes.

Let’s be honest—life insurance probably isn’t on your list of fun things to research. But locking in a policy now could mean huge peace of mind for your family down the road. And getting covered is actually a lot easier than you might think.

With Best Money’s term life insurance marketplace, you can compare top-rated policies in minutes and find coverage that works for you. No long phone calls. No confusing paperwork. Just straightforward quotes, starting at just $7 a month, from trusted providers so you can make an informed decision.

The best part? You’re in control. Answer a few quick questions, see your options, get coverage up to $3 million, and choose the coverage that fits your life and budget—on your terms.

You already protect your car, your home, even your phone. Why not make sure your family’s financial future is covered, too? Compare term life insurance rates with Best Money today and find a policy that fits.

Profile photo for Pratik Thacker

Let's start from the beginning step wise

Step 1.declaration

x and y are declared as floating point numbers which mean 5 and 9 are considered as 5.00 nd 9.00

Step 2.declaration And assignment

z is decleared as an integer which means it cannot store floating point nos. Or simply numbers after the decimal point are ignored

In the above case external typecasting is done which is required when we want to convert a higher data type to a lower data type.

When x/y is done it produces a float number as output but to store this output into an integer typecasting is required where x/y=1.8 here is converted to

Let's start from the beginning step wise

Step 1.declaration

x and y are declared as floating point numbers which mean 5 and 9 are considered as 5.00 nd 9.00

Step 2.declaration And assignment

z is decleared as an integer which means it cannot store floating point nos. Or simply numbers after the decimal point are ignored

In the above case external typecasting is done which is required when we want to convert a higher data type to a lower data type.

When x/y is done it produces a float number as output but to store this output into an integer typecasting is required where x/y=1.8 here is converted to an integer and just 1 is stored

So now z=1

Step 3.executing the switch case

z is passed as a parameter so case 1 is executed.

Case 1 performs the following operation i.e x=x+2

So now value of x is 11 or x=11.0

Step 4.output is 11.0

Now dr is no break statement so the control goes to the next case statment

Step 5.case 2 is executed

X=x+3

Now x=14.0

Step 5.default is executed also

X=x+1

Now x=15.0

Languages like C,C++ and java supports the concept of fall through which means if you do not mention a break statement the case is executed and all the cases and default after that is executed too…

Thanx Varishta Das for pointing out the mistake

Thanx Ekesh Bahuguna for correction

Profile photo for Gabor Jakab

The init method is a life cycle callback method of the Servlet class, it is called by the servlet container to initialize the servlet instance. After initialization the servlet instance is in the ready state, it is placed into service (the service method is invoked with each matching request).

The init method is called only once after the servlet class is loaded by the Java class loader, after a servlet instance is created in the servlet container and before the servlet class is used (service, doGet, doPost… methods are called)!

It is possible and a typical practice to override the init method i

The init method is a life cycle callback method of the Servlet class, it is called by the servlet container to initialize the servlet instance. After initialization the servlet instance is in the ready state, it is placed into service (the service method is invoked with each matching request).

The init method is called only once after the servlet class is loaded by the Java class loader, after a servlet instance is created in the servlet container and before the servlet class is used (service, doGet, doPost… methods are called)!

It is possible and a typical practice to override the init method in the Servlet implementation class. With the init method the ServletConfig object is available in the servlet instance, so that the servlet configuration parameter values can be read and used in the servlet implementation.

This search engine can reveal so much. Click here to enter any name, wait for it, brace yourself.
Profile photo for Martin O'Shea

The init method actually does very little. According to Servlets Life Cycle, the init method:

“is designed to be called only once. It is called when the servlet is first created, and not called again for each user request. So, it is used for one-time initializations, just as with the init method of applets.

The servlet is normally created when a user first invokes a URL corresponding to the servlet, but you can also specify that the servlet be loaded when the server is first started.

When a user invokes a servlet, a single instance of each servlet gets created, with each user request resulting in

The init method actually does very little. According to Servlets Life Cycle, the init method:

“is designed to be called only once. It is called when the servlet is first created, and not called again for each user request. So, it is used for one-time initializations, just as with the init method of applets.

The servlet is normally created when a user first invokes a URL corresponding to the servlet, but you can also specify that the servlet be loaded when the server is first started.

When a user invokes a servlet, a single instance of each servlet gets created, with each user request resulting in a new thread that is handed off to doGet or doPost as appropriate. The init() method simply creates or loads some data that will be used throughout the life of the servlet.”

Profile photo for Vaibhav Kumar

I’m assuming that you have written above code in main().

The output will be 15.0;

There is no break statement, so all case statement will be executed.

float x=9;

float y=5;

int z= (int)(x/y); // Z = 1

switch(z)

{

case 1: x=x+2; // x= 11.0

case 2: x=x+3; // x= 14.0

default: x=x+1; // x= 15.0 It will be output

}

System.out.println(x); // output x = 15.0

Profile photo for Marc Hammes

Like many of you reading this, I’ve been looking for ways to earn money online in addition to my part-time job. But you know how it is – the internet is full of scams and shady-grady stuff, so I spent weeks trying to find something legit. And I finally did!

Freecash surprised me in all the right ways. I’ve earned over $1,000 in one month without ‘living’ on the platform. I was skeptical right up until the moment I cashed out to my PayPal.

What is Freecash all about?

Basically, it’s a platform that pays you for testing apps and games and completing surveys. This helps developers improve their appl

Like many of you reading this, I’ve been looking for ways to earn money online in addition to my part-time job. But you know how it is – the internet is full of scams and shady-grady stuff, so I spent weeks trying to find something legit. And I finally did!

Freecash surprised me in all the right ways. I’ve earned over $1,000 in one month without ‘living’ on the platform. I was skeptical right up until the moment I cashed out to my PayPal.

What is Freecash all about?

Basically, it’s a platform that pays you for testing apps and games and completing surveys. This helps developers improve their applications while you make some money.

  • You can earn by downloading apps, testing games, or completing surveys. I love playing games, so that’s where most of my earnings came from (oh, and my favorites were Warpath, Wild Fish, and Domino Dreams).
  • There’s a variety of offers (usually, the higher-paying ones take more time).
  • Some games can pay up to $1,000 for completing a task, but these typically require more hours to finish.
  • On average, you can easily earn $30–50/day.
  • You pick your options — you’re free to choose whatever apps, games, and surveys you like.

Of course, it’s not like you can spend 5 minutes a day and become a millionaire. But you can build a stable income in reasonable time, especially if you turn it into a daily habit.

Why did I like Freecash?

  • It’s easy. I mean it. You don’t have to do anything complicated. All you need is to follow the task and have some free time to spend on it. For some reason, I especially enjoyed the game Domino Dreams. My initial goal was to complete chapter 10 to get my first $30, but I couldn’t stop playing and ended up completing chapter 15. It was lots of fun and also free money: $400 from that game alone.
  • No experience needed. Even if you’ve never done any ‘testing’ before, you can do this. You get straightforward task descriptions, so it’s impossible to go wrong. A task you might expect is something like: Download this game and complete all challenges in 14 days.
  • You can do it from anywhere. I was earning money while taking the bus, chilling on the couch, and during my breaks.
  • Fast cashing out. I had my earnings in my PayPal account in less than 1 day. I’m not sure how long it takes for other withdrawal methods (crypto, gift cards, etc.), but it should be fast as well.
  • You can earn a lot if you’re consistent. I’ve literally seen users in the Leaderboard making $3,000 in just one month. Of course, to get there, you need time, but making a couple of hundred dollars is really easy and relatively fast for anyone.

Don’t miss these PRO tips to earn more:

I feel like most users don’t know about these additional ways to make more money with Freecash:

  • Free promo codes: You can follow Freecash on social media to get weekly promo codes for free coins, which you can later exchange for money.
  • Daily rewards and bonuses: If you use the platform daily, you’ll get additional bonuses that help you earn more.
  • In-app purchases to speed up processes: While playing, you can buy items to help speed up task completion. It’s optional, but it really saved me time, and I earned 4x more than I spent.
  • Choose the highest-paying offers: Check New Offers and Featured Offers to get the best opportunities that pay the most.

Honestly, I still can’t believe I was able to earn this much so easily. And I’ve actually enjoyed the whole process. So, if you’re looking for some truly legit ways to earn money online, Freecash is a very good option.

Profile photo for Shaikh Hamid

to send your messages. the messages like HTML format.

the response work order on HttpServletRequest request and HttpServletResponse response object.

Note : - request and response are object of Http Services.

Profile photo for Roy Tang

This will largely depend on the implementation of the servlet container. It will be called whenever the servlet container deallocates the servlet instance. The servlet spec does not specify when this should happen. The servlet instance may be active for the entire duration that the servlet container is up, or it may deallocate instances earlier for performance purposes

Profile photo for Raghavan Alias Saravanan M

It is more like Garbage Collection activity if you can have an analogy. This method will be called when the Servlet Container puts the Servlet Instance out of memory once its life time is over. It is purely dependent on the Servlet Vendor with their implementation. As a programmer you be rest assured that whenever a Servlet instance needs to be taken off the memory ( be it during container shut down or the instance going away), this method will be called.

Why do you need to call a class public method in servlet? Why do you want to allow snoopers like this? Go for MVC architecture develop a robust application.

Profile photo for Piyush

Lets move step-by-step in order to find the output of the your code :

float x=9; → float variable x is assigned value as: 9.0

float y=5; → float y is assigned value as: 5.0

int z = (int)(x/y); → first computes (9/5) i.e 1.8 and the result is converted into integer type i.e 1.

switch(z) →takes the above computed value i.e 1

{

case 1: x=x+2; → as it verifies the case condition, this would be ‘true’, giving value of x=9.0+2 = 11.0

case 2: x=x+3; → since there is no break statement encountered, the execution moves to this case as well, giving value of x=11.0+3 = 14.0

default: x=x+1; → again no break sta

Lets move step-by-step in order to find the output of the your code :

float x=9; → float variable x is assigned value as: 9.0

float y=5; → float y is assigned value as: 5.0

int z = (int)(x/y); → first computes (9/5) i.e 1.8 and the result is converted into integer type i.e 1.

switch(z) →takes the above computed value i.e 1

{

case 1: x=x+2; → as it verifies the case condition, this would be ‘true’, giving value of x=9.0+2 = 11.0

case 2: x=x+3; → since there is no break statement encountered, the execution moves to this case as well, giving value of x=11.0+3 = 14.0

default: x=x+1; → again no break statement encountered, the execution moves to this step, giving value of x=14.0+1 = 15.0

}

System.out.println(x); → prints 15.0 as output.

Hope this explains you the output and the reason for “WHY?” !! :)

Feel free to ask for any doubts.

Profile photo for Akshay Shetye

You can use it to initialiaze anything as u wish. Servlet container will ensure that it calls init method when the container starts . That's all about it.

About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025