If you're going to modify a servlet, you'll need to edit and recompile the classes that you're changing - and chances are that will include the main application class. Which means you need to have access to the source. Not a problem if you're a developer of the product, but could be an issue if it's someone else's code. Let's assume, though, for this article that you do have access to the source.
Do you just edit and compile, then?
Sorry - no - it's not that simple ...
1. Even though you may be compiling on a different machine to you'll be running on, you will need to have all the classes called available on the compile system. Which means all the application classes called, and also library classes which are used, need to be available. (Ironically - just to satisfy the compiler that your code is right!). In particular, many of the servlet classes may need to be sourced; from Tomcat, where the distribution includes servlet-api.jar , is the easiest source. And you then need that jar on your CLASSPATH.
2. You need to copy the compiled output into the WEB-INF/classes directory of your web application so that it's accessible to Apache Tomcat (or whatever other Servlet container you're using)
3. If you're renaming you application of its URL (perhaps you're putting up a test version alongside the production one), you'll need to add to / change your WEB-INF/web.xml file to provide an updated URL to class mapping
4. You're likely to need to stop and start Tomcat - or at least the web application - to clear cahces and reload, unless the URL and class names are brand new.
Details of these operations / stages are includes as comments on the top of a new servlet I set up on today's Java Course
- the full code, and the instructions - are [here]
. (written 2010-11-12)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesA507 - Web Application Deployment - Java - Servlets and JSPs 
Servlet v JSP (Java Server Page). What is the difference? - (2013-02-06) 
Using JSPs, Tag Libraries, Java Beans, Tomcat in one short example - (2009-12-04) 
What is a JSP tag library? - (2009-05-01) 
New servlet from old - (2005-10-28)A653 - Web Application Deployment - Tomcat - Configuring Web Applications 
Tips on Tomcat - moving applications around - (2013-02-05) 
Changing the 404 - file not found - page in Tomcat - (2009-03-18) 
javax.servlet cannot be resolved - how to solve - (2008-11-26) 
Default file (MiMe types) for Apache httpd and Apache Tomcat - (2008-03-04) 
Extra public classes in deploying Apache httpd and Tomcat - (2008-02-24) 
What are WEB-INF and META-INF directories? - (2007-05-18) 
Straight from the .jar - (2007-02-16) 
Java beans and classes, .war and .jar files - (2007-02-10) 
Apache httpd and Apache Tomcat together tips - (2006-12-24) 
tar, jar, war, ear, sar files - (2006-06-10) 
Changing Tomcat's web.xml and reloading a web application - (2005-10-15)J901 - Java - Servlets 
Reading and writing cookies in Java Servlets and JSPs - (2010-02-26)J906 - Java - Servlets in More Detail 
Distributing the server load - yet ensuring that each user return to the same system (Apache httpd and Tomcat) - (2011-05-18) 
The Multiple Inheritance Conundrum, interfaces and mixins - (2010-04-11) 
Servlet life cycle, and Java Servlet variable scope - (2009-05-16) 
Java (JSP and Servlet examples) live on our server - (2008-02-23) 
Single login and single threaded models - Java and PHP - (2008-01-04)
Some other Articles
String handling - from first steps to practical examplesWhat is a universal superclass? Java / Perl / Python / Other OO languagesJava Beans, tag libraries and JSPs - what and why.After Course Resources - do we publish sample answers. Example from Java Exceptions module.Changing a Servlet - more that just editing and compilingGathering information - logging - with log4j. First steps.Least Common Ancestor - what is it, and a Least Common Ancestor algorithm implemented in PerlJava - basic rules for arithmetic, variables and conversionDoing several things at the same time - Java threadsFresh Paint - Java Arrays