How do I resolve this ?
HTTP Status 500 -
type Exception report
description The server encountered an internal error that prevented it from fulfilling this request.
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.18 logs.
Is your servlet extending GenericServlet or HttpServlet?
What is your code for the init() method?
Can you provide the full exception from the log?
Are there any other messages in the log from startup etc?
(clutching at straws) - you don't have any of the servlet libraries in your WEB-INF/lib folder do you?
Since I'm new to the servlet technologies and Eclipse (i was using Netbeans until recently), while creating a servlet, I was clicking on the init check box so Eclipse would make init() method automatically.
The Eclipse made the init() method like this and that would cause me problems
so I change it to
and that solved my problem.
Bear Bibeault wrote:ACK!!!
Never, ever, ever, use instance variables in a servlets. Declare your list inside the method.
Using instance variables makes the servlet non-thread-safe and multiple requests to your servlet will all stomp all over each other.
Thanks for the advice.
stevan pivnicki wrote:Is that necessary only for ArrayLists or for all class declarations inside the servlet ?
Never, ever, ever, use instance variables in a servlets.
What made you think that advice only applied to ArrayList variables? Of course, it applies to all variables.
More info on why: because a single instance of a servlet vcan be used to process multiple simultaneous requests in separate threads, instance variables, of which there will be only one copy, will be used by all the threads. So one thread might set a variable to one value, another will set it to another value, then the first thread gets the wrong value, and well, all hell breaks loose.