Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Naresh
Servlet example
1 Answer(s)      6 years and 4 months ago
Posted in : Servlet Interview Questions


Servlet Example


Advertisement
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
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
Advertisements
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...; for writing simple hello world example of servlet. Step1 : Write servlet, a POJO
@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       Example program to demonstrate Logging Filter This example illustrates how one can write Logging Filter servlet to provide
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
hello world in Servlet. Let us explain this by a hello world example using Servlet. Example :  Hello world example in Servlet import java.io.*; import...Servlet  hello world example This tutorial will help you to understand
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... of Asynchronous Servlet 3.0 Example.</h3> </body> </html>
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
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... is given at the time of servlet creation by separating comma( , ). Example
@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
AsyncContext Example
In this section, you will learn about Servlet 3.0 AsyncContext using a complete 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
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
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. Example :  In this example we are using
@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
Example
Example  JDBC in Servlet examples.   Hi Friend, Please visit the following link: Servlet Tutorials Here you will get lot of examples including jdbc servlet examples. Thanks
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
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
in servlet   Hello Friend, Please visit the following link: http://www.roseindia.net/servlets/servlet-read-file.shtml Here you will get an useful example. Thanks
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
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
Servlet  What is Servlet
example
example  example on Struts framework
example
example  example on Struts framework
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
Servlet
Servlet  how to navigate one servlet page to another servlet page
example
example  i need ex on struts-hibernate-spring intergration example   Struts Spring Hibernate Integration
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
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
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  How many times the servlet is accessed
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
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     
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 want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
 

 

 

DMCA.com