Servlet example

Servlet example

Servlet Example

View Answers

April 10, 2008 at 7:46 PM

Hi friend

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
version="2.4">

<servlet>
<servlet-name>MultiInstance</servlet-name>
<servlet-class>MultipleInstances</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MultiInstance</servlet-name>
<url-pattern>/MultipleInstances</url-pattern>
</servlet-mapping>

</web-app>


MultipleInstances.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MultipleInstances extends HttpServlet {

static int classCount = 0; // shared by all instances
int count = 0;
static Hashtable instances = new Hashtable(); // also shared

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();

count++;
out.println("Since loading, this servlet instance has been accessed " + count + " times.");
instances.put(this, this);
out.println("There are currently " + instances.size() + " instances.");
classCount++;
out.println("Across all instances, this servlet class has been " + "accessed " + classCount + " times.");
}
}


---------------------------

read for more information.

http://www.roseindia.net/servlets/









Related Tutorials/Questions & Answers:
Example questions of JSP & Servlet
Example questions of JSP & Servlet  Give me some JSP & Servlet Question and their answers
Example of Getting request URL in a servlet
Example of Getting request URL in a servlet  One servlet can be configured to handle a set of requests. So, in Servlet you have to get the URL...()); Check the tutorial Java Servlet : Get URL Example for complete web application
Advertisements
A simple example of log4j for Servlet
A simple example of log4j for Servlet       This Example shows you how to create a log in a Servlet. Description of the code: Logger.getLogger(): Logger class is used
Hit Counter Servlet Example
Hit Counter Servlet Example       This example illustrates about counting how many times the servlet is accessed. When first time servlet (CounterServlet) runs then session is created
need a jsp example - JSP-Servlet
need a jsp example  I need a jsp example to send a voice message or a audio .wav file from my pc to a mobile phone
provide example in J2ee/jsp - JSP-Servlet
provide example in J2ee/jsp  how to manage search options page in jsp using back end as oracle/sql? i am using multiple search options. so please provide code for this or tutorial
Java Servlet : Hello World Example
Java Servlet : Hello World Example In this tutorial, we are discussing about Servlet with simple Hello World Example. Java Servlet : A servlet is web... are the steps  for writing simple hello world example of servlet. Step1 : Write
@WebListener Annotation Servlet Example
@WebListener Annotation Servlet Example In this tutorial you will learn what... and servlet 3.0 (Java EE6). The example given below will demonstrate you how to implement a listener interface in servlet. In this example I will use
Logging Filter Servlet Example
Logging Filter Servlet Example   ... This example illustrates how one can write Logging Filter servlet to provide...; In this example there is LoggingFilterExample servlet which is writing Remote
Context Log Example Using Servlet
Context Log Example Using Servlet       This example illustrates about how to use of Context Log in servlet. Context Log is used to write specified message
Response Filter Servlet Example
Response Filter Servlet Example       This Example shows how to use of response filter in  Java Servlet. Filter reads own initial parameters and adds its value
Servlet hello world example
example using Servlet. Example :  Hello world example in Servlet import...Servlet  hello world example This tutorial will help you to understand the Servlet from scratch. Servlet is a server side programming language. Servlet
jsp maps api example - JSP-Servlet
jsp maps api example  Can u give a complete working example on usage of JSP GOOGLE MAP API
JSP Paging Example in Datagrid - JSP-Servlet
JSP Paging Example in Datagrid  Hi, I have tested JSP Paging Example in Datagrid which is available at the following url which i am able to run it successfully. http://www.roseindia.net/jsp/paging.shtml When i try
Bit torrent technology code example - JSP-Servlet
the following example which asks user to upload an image on the server and then you
JSP Paging Example in Datagrid - JSP-Servlet
JSP Paging Example in Datagrid  Hello, This is with refernece to the paging smaple provided on the URL http://www.roseindia.net/jsp/paging.shtml... ========================================= Paging Example Using Datagrid th a:link
Servlet 3 Async Example
Servlet 3 Async Example In this tutorial you will learn about the asyncSupported attribute in servlet. In servlet 3 an annotation is used for an alternative... this is a demo example of Asynchronous Servlet 3.0 Example.</h3> </body>
Servlet Example To Update Mysql Clob Data
Servlet Example To Update Mysql Clob Data    This example shows how to update CLOB data in the database. In our example, servlet InsertClobExample takes url for the CLOB data (the url
AsyncContext Example
In this section, you will learn about Servlet 3.0 AsyncContext using a complete example
Servlet Annotation Hello World Example in Eclipse
Servlet Annotation Hello World Example in Eclipse In this tutorial you will learn how to create an annotated servlet in web applications. In this example I... servlet using the Eclipse Helios IDE and the Tomcat7 application server. Because
@WebInitParam Annotation Servlet Example
@WebInitParam Annotation Servlet Example In this tutorial you will learn how to use the init parameters in servlet 3.0 specificattion. In the older version of servlet init parameters specifications were given into the web.xml file
J2ME Servlet Example
J2ME Servlet Example       This is the simple servlet tutorial. In this tutorial we shows you, how to create the servlet and implement it with the midlet. In this servlet
JSON and Servlet example
JSON and Servlet example       In the previous section of JSON-Java example you have... we will tell you how to use JSON classes for creating Servlet. In this example
Servlet Example To Insert Mysql Clob Data
Servlet Example To Insert Mysql Clob Data    This example shows how to insert CLOB data in the database. In our example, servlet InsertClobExample takes url for the CLOB data (the url
Java Servlet : Get URL Example
Java Servlet : Get URL Example In this tutorial, You will learn how to get url of servlet. Servlet getRequestURL : getRequestURL() method reconstruct... can add query string parameters.ADS_TO_REPLACE_1 Example :  
Session Tracking Servlet Example
Session Tracking Servlet Example In this tutorial you will learn how to track session in servlet. Session tracking is required for identifying the client... object. Here I am using the session object. Here I am giving the simple example
@WebFilter Servlet Example
@WebFilter Servlet Example In this tutorial you will learn what the difference is in the registration of Filter in older version and servlet 3.0 (Java EE6). The example given below will demonstrate you how to use a @WebFilter
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
servlet
in servlet   Hello Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/servlets/servlet-read-file.shtml Here you will get an useful example. ThanksADS_TO_REPLACE_2
servlet
servlet   Dear Deepak, is it compulsary to write the sevice() becoz i ve seen some example which does not ve sevice()..is it tue? plz replay me with thanks praveen
Servlet setAttribute & getAttribute method example
Servlet setAttribute & getAttribute method example In this tutorial you... in servlet. In the example given below I want to carry some information from one servlet to another servlet. For this solution first I created two servlet in one
Servlet
Servlet  What is Servlet
File Upload Servlet 3.0 Example
File Upload Servlet 3.0 Example In this tutorial you will learn how to upload a file in servlet 3.0 In this example I have used the @MultipartConfig annotation to upload the file. Earlier versions than the servlet 3.0 specification were
Servlet
Servlet  how to navigate one servlet page to another servlet page
Example
Example  JDBC in Servlet examples.   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Servlet Tutorials Here you will get lot of examples including jdbc servlet examples. ThanksADS_TO_REPLACE_2
Java runtime example - JSP-Servlet
JSP - JSP-Servlet
JSP & Servlet Example Code  Need example of JSP & Servlet
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  How many times the servlet is accessed
log4j example
log4j example       This Example shows you how to create a log in a Servlet. Description of the code: Logger.getLogger(): Logger class is used for handling the majority
example
example  example on Struts framework
example
example  example on Struts framework
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
How send different files to browser at same time ..example(pdf&html) want display in same request using servlet
at same time ..example(pdf&html) want display in same request using servlet...How send different files to browser at same time ..example(pdf&html) want display in same request using servlet  package com.readfiles; import
Java : Servlet Tutorials - Page 2
We are providing you an example. In the given example, an object of Servlet...; Upload Image using Servlet In this example program a form... Java : Servlet Tutorials     
Java Servlet : Reading Form Data Example
Java Servlet : Reading Form Data Example In this tutorial, we are discussing about reading form data of a servlet. Reading Form Data : There are three methods of servlet to handle the form data. These are listed below -ADS
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help

Ads