Home Servlets Java : Servlet Tutorials
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java : Servlet Tutorials

Advertisement
History of Web application Earlier in client- server computing, each application had its own client program and it worked as a user interface and need to be installed on each user's personal computer.

Java : Servlet Tutorials

     

Java Servlets it Java technology for creating the dynamic web applications. Java Servlets are server side components in Java that runs on Servlet enabled web server such as Tomcat, Jetty, Websphere etc.. Java Servlet is much faster then CGI and Perl since it runs in the same JVM. In case of CGI and Perl separate memory space is allocated for execution of the program which reduces it's performance.

For running the Java Servlet you can download the latest version of Tomcat server and install on your computer. It's much easier to use Tomcat for learning Java Servlet. These step-by-step tutorials will teach you Java Servlet and impart the knowledge necessary for developing and testing Java Servlet. After learning these tutorials you will be able to start using Java Servlet in your web projects.

In this section you will find several tutorials of Java Servlet.

First let's understand about web and web applications.

  1. History of  Web application
    Earlier in client- server computing, each application had its own client program and it worked as a user interface and need to be installed on each user's personal computer.
       
  2. Introduction to Web Server
    Web Server is a computer on the World Wide Web that stores Html documents that can be retrieved via a Web browser. It is a computer that delivers web pages.
      
  3. What is a Container
    Container are nothing but a Java application which controls servlets. Tomcat is one of the example of a container. It is the container which calls the servlet's methods like doPost() and doGet().
       

After understanding the basics of web and web application development we will learn about the Servlet technology of Java. The Servlet technology helps the developer to write dynamic web applications. JSP is also compiled into Servlet before it is executed on the container.

Advertisement

Let's get started with the Servlet technology. You can learn Java Servlet here with help of example programs given below:

  1. Overview of Servlets
    What is servlet?
      
    Methods of Servlet

    Life Cycle of Servlet

    Features of Servlet 2.4 

    Features of Servlet 2.5

    Features of Servlet 3.0

    Advantages of Java Servlets

    Advantages of Servlets over CGI

    Servlet 3.0 Complete Tutorial


  2. Quick get to Servlet
    Servlets overview
     

    Introduction to Server Side programming
      
    Introduction to Java Servlets
      
    Installing Configuring and Running Servlets    
        
  3. How to run a Servlet?
    Install the tomcat server in a directory in which you want to install and set the classpath.for the variable JAVA_HOME in the environment variable.
        
  4. Writing Hello World
    We should start understanding the servlets from the beginning. Lets start by making one program which will just print the "Hello World" on the browser. Each time the user visits this page it will display "Hello World" to the user.
      
  5. Displaying Date in Servlet
    In this example we are going to show how we can display a current date and time on our browser. It is very easy to display it on our browser by using the Date class of the java.util package.
         
  6. Simple Counter In Servlet
    In this example we are going to know how we can make a program on counter which will keep track how many times the servlet has been accessed.
        
  7. A Holistic counter in Servlet
    In this program we are going to make a such a servlet which will count the number it has been accessed and the number of threads created by the server.
       
  8. Counter in Init() Method
    In this program we are going to make a such a servlet which will count and displays the number of times it has been accessed and by reading the init parameter to know from where the counting will begin.
      
  9. Snooping the server
    To display the name of the server you are using use the method getServerName() of the ServletRequest interface. To display the server port number use the method getServerPort().
       
  10. Snooping Headers
    In this program we are going to going to make a servlet which will retrieve all the Http request header.
      
  11. Dice Roller
    We are going to make one program on the dice roller in which the number in the dice will be selected randomly. 
       
  12. Getting Init Parameter Names
    Whenever the container makes a servlet it always reads it deployment descriptor file i.e. web.xml. Container creates name/value pairs for the ServletConfig object.  Once the parameters are in ServletConfig they will never be read again by the Container.
        
  13. Passing Parameter Using Html Form
    This is a very simple example in which we are going to display the name on the browser which we have entered from the Html page.
       
  14. Multiple values for a single parameter
    In our program it may be that we may have multiples values for a single parameter like in checkboxes.
      
  15. Time Updater in Servlet
    In this program we are going to make one program on servlet which will keep on updating the time in every second and the result will be displayed to you. 
       
  16. Send Redirect in Servlet 
    In this example we are going to make one html in which we will submit the user name and his password. The controller will check if the password entered by the user is correct or not.
        
  17. Session Tracking
    As we know that the Http is a stateless protocol, means that it can't persist the information. It always treats each request as a new request. In Http client makes a connection to the server, sends the request., gets the response, and closes the connection.
           
  18. To Determine whether the Session is New or Old
    In this program we are going to make one servlet on session in which we will check whether the session is new or old.
       
  19. Pre- Existing Session
    In this example we are going to find out whether the session is pre- existing or not. 
          
  20. Session Last Accessed Time Example
    This example illustrates to find current  access time of session  and last access time of session. Sessions are used to maintain state and user identity across multiple page requests.
      
  21. Get Session Id
    In this example we are going to make a program in which we will find the session id which was generated by the container. 
      
  22. Display session value Using Servlet
    Sometime while developing web application it is necessary to interact with the different values of the Session object. In this example we will explore the different values of the Session object and then learn how to use it in our programming code.
       
  23. 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 and value of the counter will be zero and after again accessing of servlet  the counter value will be increased by one.
      
    Connection with the Database
         
  24. Inserting Data In Database table using Statement
    In this program we are going to insert the data in the database from our java program in the table stored in the database. 
             
  25. Retrieving Data from the table using Statement
    In this program we are going to fetch the data from the database in the table from our java program.
        
  26. Inserting data from the HTML page to the database
    In this program we are going to make program in which we are going to insert the values in the database table from the html form.
         
  27. Retrieving Data from the table using PreparedStatement
    In this program we are going to fetch the data from the database in the table from our java program using PreparedStatement
     
  28. Getting Columns Names using Servlets
    Consider a situation where there is a need to know about the name of the columns without touching our database. As we are the programmers so why we need to worry about the database.
      
  29. Getting Number of Columns
    Consider a situation where there is a need to know about the number of columns in the table without touching our database. As we are the programmers so why we should worry about the database.
       
  30. Getting Number of Rows
    Consider a situation where we want to know about the number of rows in the particular database table without touching our database.
    We want to find out the number of rows without going touching our back- end.
      
  31. Deleting Rows From Table
    Consider a situation where we have entered some wrong data and in later situation it starts giving problem to the organization.
       
  32. Deleting All Rows From the database Table
    Consider a situation where we have entered some wrong data and in later situation it starts giving problem to an organization or may become useless after sometime . Rather than go through with that data its better to delete that data.
         
  33. How to add a column in a table
    Consider a situation where the requirement of the client gets changed and you have asked to modify the structure of the table. In reality it is the work of the database administrator but as a Java programmer you should know how you can modify the structure of the table.
         
  34. How to delete a table in mysql
    Consider a situation where we need to delete a table from a database.
      
  35. changing column name
    consider a scenario where we have a table and it consists some data and a situation arises where there is a need to change the name of the column.   
      
  36. insert into statement in sql using servlets
    In this tutorial we are going to learn how we can insert a value from a html form in the table stored in the database.   
                 
  37. join tables mysql using servlets
    In this program we are going to join the two table by using the servlets and the result will be displayed in the browser.
            
  38. Natural Left Join using servlets
    In this program we are going to join the two table by using the servlets and the result will be displayed in the browser. This join will be natural left join. 
       
  39. Natural Right Join using servlets
    In this program we are going to join the two table by using the servlets and the result will be displayed in the browser. This join will be natural right join.
               
  40. Difference between Servlet 2.4 and Servlet 2.5
    In this tutorial you will know  the difference between Servlet 2.4 and Servlet 2.5
               
  41. Get And Post Method of Http
    The Get is one the simplest Http method. Its main job is to ask the server for the resource. The Post method is more powerful request. By using Post we can request as well as send some data to the server.
           
  42. Servlets Links
    Servlets are the Java platform technology of choice for extending and enhancing Web servers. Servlets provide a component-based, platform-independent method for building Web-based applications, without the performance limitations of CGI programs. And unlike proprietary server extension mechanisms (such as the Netscape Server API or Apache modules), servlets are server- and platform-independent.
        
  43. Select Color
    In this program we are going to selected the various color and on the basis of the selection the output will be displayed to the user.
                  
  44. sendRedirect
    In send Redirect whenever the client makes any request it goes to the container, there the container decides whether the concerned servlet can handle the request or not. 
           
  45. Send Redirect in Servlet
    When we want that someone else should handle the response of our servlet, then there we should use sendRedirect() method.
         
  46. Random Redirector
    In this program we are going to make such a servlet which will be responsible to select a site randomly from the list of sites you have entered. Note that the selection of the site will be randomly.
            
  47. Servlet Context
    ServletContext is a interface which helps us to communicate with the servlet container. There is only one ServletContext for the entire web application and the components of the web application can share it.     
      
  48. Servlet Context Listener
    ServContextListener is a interface which contains two methods: public void contextInitialized(ServletContextEvent event) and
    public void contextDestroyed(ServletContextEvent event).
      
  49. ServletContextListener example
    ServletContextListener is notified when the context is initialized. It will be notified when the context is destroyed. It closes the database connection.
           
  50. ServletContextAttributeListener
    The listener ServletContextAttributeListener is an interface and extends the java.util.EventListener class. This listener come into existence when this interface receives notifications of changes to the attribute list on the servlet context of a web application.
         
  51. HttpSessionListener
    HttpSessionListener is an interface which extends java.util.EventListener class. The main purpose of this listener is to notify whenever there is a change in the list of active sessions in a web application..
         
  52. HttpSessionListener example
    Before going into the details of the SessionListener we should firstly know about the sessions. Whenever a client makes a request for any resources to the server, the server receives the request and processes the request and sends back the response.
      
  53. HttpSessionAttributeListener
    The listener HttpSessionAttributeListener is an interface and extends the java.util.EventListener class. This listener will be called by the container whenever there there will be change to the attribute list on the servlet session of a web application.
     
  54. HttpSessionAttributeListener Example
    This listener is used when we want to know when a attribute has been added in a session, when a attribute has been removed and when it is replaced by another attribute.
       
  55. httpsessionbindinglistener
    HttpSessionBindingListener is a interface which extends java.util.EventListener interface. The purpose of the this interface is to notify an object when it is bound to or unbound from a session. 
        
  56. httpsessionbindinglistener example
    This interface has two methods: valueBound(HttpSessionBindingEvent event) and valueUnBound(HttpSessionBindingEvent event).
         
  57. ServletRequestAttributeListener
    This listener is used when we want to know when a attribute has been added in a request, when a attribute has been removed and when it is replaced by another attribute.
          
  58. Inserting Image in a database Table
    Consider a case where we want that along with the name of the person and its information, his image should also come with all these things.
      
  59. Insert  Image into Database Using Servlet
    This example illustrate the process of inserting image into database table using Servlet. This type of program is useful in social networking or HR application where it is necessary to save the uploaded photograph of the user. 
     
  60. Retrieve image from database using Servlet
    In this example we will show you how to develop a Servlet that connects to the MySQL database and retrieves the image from the table. After completing this tutorial you will be able to develop program for your java based applications that retrieves the image from database.
            
      
  61. say hello in spanish
    In this program we are going to display "hello" in spanish along with the date. 
      
  62. Accessing Date In Servlet
    In this example, we are going to show how we can display a creation date of the session and last accessed date or time and id on our browser. It is very easy to display it on our browser by using the Date class of the java.util package. 
      
  63. Post Message In servlet
    In this example, we are going to implement posting massage to servlet. In the following program, you will learn how to post massage. 
         
  64. Show Parameter In Servlet
    In this section, you will learn how to send and put all parameter names into the table. The  following program uses two methods, which is described below.
     
  65. Get Parameter Name From Servlet Request
    This example illustrates about how to get parameter from jsp page in your servlet. In the jsp (parameter.jsp) page we have taken three input fields having name as firstname, lastname and middle name..
     
  66. How to connect to MySql Database from Servlet?
    In this example we will show you how to connect to MySQL database and perform select operation. You will learn the JDBC steps necessary to connect to the MySQL Database and execute the query. 
      
  67. Servlet Error Message based on user input
    In this example user is presented with a screen to enter the name. If the entered name exists in the database its displays the sucess message otherwise it displays the error message. So, you can use Servlet to check the user input against database and display the message to the user.
     
  68. Quintessential Servlet
    Quintessential servlet is not any special kind of servlet. It is just a proper and appropriate way to write a servlet. This quintessential servlet means that servlet is having accurate way of code written for an organizations servlet.
     
  69. Logging Filter Servlet Example
    This example illustrates how one can write Logging Filter servlet to provide control over log file. You can have additional controls over these log files and these all are available to use by implementing "Filter" class.
     
  70. 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 to server log file when servlet is called. In the following JSP page (message.jsp) we have simply taken a text area where user give his/her message and post the form.
     
  71. 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 to the response. Use the init-param child element of the filter element to declare the initialization parameter and its value.
     
  72. IP Filter Example
    The filter provides a basic security  mechanism for a firewall to determining what traffic passes through the firewall based on IP address details. This protects the secure network from outsiders. 
      
  73. Working with Tomcat Server
    Apache Tomcat is a famous Servlet container developed at  Apache Software  Foundation. This software is released under under the Apache Software License.
      
  74. Use of Cookie in Servlet
    The cookie class provides an easy way  for servlet to read, create, and manipulate HTTP-style cookies, which allows  servlets to store small amount of data.
      
  75. Send a Response Status in servlet
    All Response status is defined in HttpServletResponse Class. You can then use constants (response.SC_OK,response.SC_NOT_FOUND etc..) values to return process status to the browser.
           
  76. Read Cookies from Servlets
    The Cookie Class provides an easy way to read Cookies. You can use getCookies() method to retrieve all the cookies in your servlet program.
          
  77. Send Cookies in Servlets
    This section illustrates you how to send cookie in servlets. Cookies are small bits of  information that a Web server sends to a browser and that the browser returns unchanged after visiting the same page.
          
  78. How to read text file in Servlets
    In this example we will use the input stream to read the text from the disk file. The InputStreamReader class is used to read the file in servlets program.
      
  79. Check if parameter exists in servlets request
    In this example we will see how to check is parameter exists in servlets request. In this example given below we have used method getParamaterNames() of the ServletRequest interface  to find all the parameters name in the clients request.
           
  80. Accept Language and Accept Charset in Servlets
    Accept Language and Accept Char set provides a servlets to determine the language in which it will speak to the clients. A browser sends the user's language to the server using the Accept .
          
  81. Multiple Drop Down Menu Using
    In this Example we can Add and Update the Details of Employee using Servlet. We create four file employee.jsp, viewdata.jsp, EmployeeAdd.java and viewdata.java.
         
  82. Refresh a Web Page Using In Servlet
    In this simplified example we develop an application to Refresh a web Page using Servlet. We create two file timer.html and timer.java.
      
  83. How to get client's address in a servlet
    This is detailed java code to get client's address in a servlet. In this example we have used method getremoteAddr() of the ServletRequest interface which returns IP address of the client in the string format.
       
  84. Search from Database In Servlet
    In this section, we have developed an Employee Search application. We created three file search.jsp, viewSearch.jsp and Search.java. 
     
  85. Header Information available from the client in Servlet
    When a HTTP client sends a request, generally GET or POST method is specified. It can send a number of headers.
     
  86. ServletContextListener with Timer
    In this section, you will learn how to use timer with ServletContextListener to run code snippet after every 1 minute immediate after the application run. In the below eaxmple, we are using ServletContextListener with timer to run code after every 1 min. ServletContextListener  immediately starts after code execution. And the Timer class of java.util.Timer is used inside  contextInitialized() function, which runs the code after every 1 minute.

Servlet Tutorials Pages: Servlet Tutorials Page 1 | Servlet Tutorials Page 2

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 25, 2008

Ask Questions?    Discuss: Java : Servlet Tutorials   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
elango
April 11, 2011
business component development

i need objectives type questions with answer
surendra
May 24, 2011
How to connect to oracle10g from Servlet

plese help me !
saritha
June 22, 2011
servlet

excellent guide for java trainee
Supriya Patil
July 4, 2011
About this site

Actually i am very thankful to you.this site is very good and very helpful.all the concepts are explained in detail.Thank u very very much.
sathis
September 1, 2011
to learn c with basic

how to learn c with basic in your website
sujatha
March 8, 2013
web technologies

i would like to know the process how i can set database drives to connect and access through servelt to process my application
iica
December 7, 2011
dropdown example gender

Here's my code. out.println("<td>Gender:</td>"); out.println("<td><select name='gender' ><option>"+rs.getString(7)+"</option><option>Male</option><option>Female</option></select></td>"); This displays the result and the gender option Male and Female. I want to know if I can use an if statement that when Female is selected as the gender, Male should be left in the drop down.
Jonetta
March 6, 2013
DulWUbNLsp

You've really helped me understand the isuses. Thanks.
priyanka kumari
April 18, 2012
advanced java(servlet)

i want to make online shopping as my final year b.tech project.there is no error came in my sevlet program during execution but output not give proply... i want retrive image with txt field from database (saved in binary format) and display in output.if we click any radio button corressponding image with txt displayed on output. forward1 page coding for this program ang image1 is for image retreving from database i am using mysql database,server tomcat6.........plz help for my final year project... /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package pkg; import com.mysql.jdbc.PreparedStatement; import java.sql.Blob; import java.sql.ResultSet; import java.sql.Statement; import java.sql.Connection; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.sql.SQLException; import java.sql.DriverManager; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.swing.JOptionPane; /** * * @author Priyanka */ public class forward1 extends HttpServlet { /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletOutputStream out = response.getOutputStream(); response.setHeader("cache-control", "no-store"); //response.setContentType("text/html;charset=UTF-8"); String str=request.getParameter("r1").trim(); // PrintWriter pw = response.getWriter(); try { out.println( "<html>"); out.println("<head>"); out.println("<title></title>"); out.println("<meta http-equiv=Content-Type content=text/html; charset=UTF-8>"); out.println ("<link rel=stylesheet type=text/css href=css/ss7.css/>"); out.println("</head>"); out.println("<body>"); out.println("<form action=buy method=get>"); out.println("<div id=top>"); out.println("<IMG src=img/PIC.JPG width=1250 height=150/>"); out.println("</div>"); Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","root"); java.sql.Statement st1=con.createStatement(); Statement statement = con.createStatement(); PreparedStatement ps=null; //String cmd=""; if(str.equals("ladies_wear")) { ps=(PreparedStatement) con.prepareStatement("select * from wear"); } else if(str.equals("ladies_footwear")) { ps=(PreparedStatement) con.prepareStatement("select * from footwear"); } else if(str.equals("wrist_watches")) { ps=(PreparedStatement) con.prepareStatement("select * from wrist_watches"); } else if(str.equals("jewellery")) { ps=(PreparedStatement) con.prepareStatement("select * from jewellery"); } else if(str.equals("cosmetics")) { ps=(PreparedStatement) con.prepareStatement("select * from cosmetics");; } else if(str.equals("home_appliance")) { ps=(PreparedStatement) con.prepareStatement("select * from home_appliance"); } else if(str.equals("Ladies_Bag")) { ps=(PreparedStatement) con.prepareStatement("select * from ladies_bag"); } //ResultSet rs=st1.executeQuery(cmd); //Blob image=null; ResultSet resultset=ps.executeQuery(); if(resultset.next()) { out.print("<center>"); out.print("<table border=2 width=1000>"); //int bufferSize = 1024; out.println("<tr>"); out.println("<th>"); out.println("productid"); out.println("</th>"); out.println("<th>"); out.println("status"); out.println("</th>"); out.println("<th>"); out.println("price"); out.println("</th>"); out.println("<th>"); out.println("description"); out.println("</th>"); out.println("<th>"); out.println("picture"); out.println("</th>"); out.println("<th>"); out.println("categories"); out.println("</th>"); out.println("<th>"); out.println("size"); out.println("</th>"); out.println("<th>"); out.println("Choose"); out.println("</th>"); out.println("</tr>"); while(resultset.next()) { out.print("<TR>"); String str1=resultset.getString(1); out.print("<TD>"+str1+"</TD>"); out.print("<TD>"+resultset.getString(2)+"</TD>"); out.print("<TD>"+resultset.getString(3)+"</TD>"); out.print("<TD>"+resultset.getString(4)+"</TD>"); out.print("<TD><img src='image1?proid="+str1+"' width='50' height='50' /></TD>"); out.print("<TD>"+resultset.getString(6)+"</TD>"); out.print("<TD>"+resultset.getString(7)+"</TD>"); out.println("<TD>"); out.println("<input type=checkbox name="+resultset.getString(1)+">"); out.println("</TD>"); out.print("</TR>"); //} } out.print("</TABLE>"); out.println(" <div id=bottom align=center>"); HttpSession ses=request.getSession(true); ses.setAttribute("cat", str); String name=(String)ses.getAttribute("uname"); //out.println(name); //out.println("<input type=hidden name=h1 value="+name+">"); out.println("<input type=submit value=ADD TO CART >"); out.println("</div>"); out.println("</form>"); out.println("</body>"); out.println("</html>"); } } catch(Exception e){out.print(e.getMessage());} } } image1 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package pkg; import java.io.*; import java.sql.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author S O M D E B */ public class image1 extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { InputStream sImage; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bank", "root", "root"); // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Connection con=DriverManager.getConnection("jdbc:odbc:picdemo","sa","niit"); PreparedStatement psmnt=null; String str=request.getParameter("r1"); if(str.equals("ladies_wear")) { psmnt = (PreparedStatement)con.prepareStatement("SELECT picture FROM wear where productid=?"); } else if(str.equals("ladies_footwear")) { psmnt = (PreparedStatement)con.prepareStatement("SELECT picture FROM footwear where productid=?"); } psmnt . setString(1, request.getParameter("proid")); ResultSet rs = psmnt.executeQuery(); if(rs.next()) { byte[] bytearray = new byte[1048576]; int size=0; sImage = rs.getBinaryStream(1); response.reset(); response.setContentType("image/jpeg"); while((size=sImage.read(bytearray))!= -1 ) { response.getOutputStream().write(bytearray,0,size); } } }catch(Exception ex){} } }
vanit
May 11, 2012
how to convert java program to servlate

ok
Vaishu
June 14, 2012
code for exception handling

// Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; // Extend HttpServlet class public class ErrorHandler extends HttpServlet { // Method to handle GET method request. public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Analyze the servlet exception Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); String servletName = (String) request.getAttribute("javax.servlet.error.servlet_name"); if (servletName == null){ servletName = "Unknown"; } String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri"); if (requestUri == null){ requestUri = "Unknown"; } // Set response content type response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Error/Exception Information"; String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n"; out.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n"); if (throwable == null && statusCode == null){ out.println("<h2>Error information is missing</h2>"); out.println("Please return to the <a href=\"" + response.encodeURL("http://localhost:8080/") + "\">Home Page</a>."); }else if (statusCode != null){ out.println("The status code : " + statusCode); }else{ out.println("<h2>Error information</h2>"); out.println("Servlet Name : " + servletName + "</br></br>"); out.println("Exception Type : " + throwable.getClass( ).getName( ) + "</br></br>"); out.println("The request URI: " + requestUri + "<br><br>"); out.println("The exception message: " + throwable.getMessage( )); } out.println("</body>"); out.println("</html>"); } // Method to handle POST method request. public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
SHARU KH
July 16, 2012
WANT TO KNOW MORE ABOUT SERVLET

DISTINGUISH BETWEEN SESSION TRACKING AND COOKIES
krishan suryavanshi
July 21, 2012
servlet

hoow to upload file and image in oracle database with servlet.
Joyce
June 15, 2013
vhdVzUIIvB

That insgiht's just what I've been looking for. Thanks!
Ankit
October 20, 2012
Java servlet

Here, This site provides very useful information for java begineers to learn the every topic in deatil. You can find article for Java Servlet here.. http://techdistance.com/java-servlet-basic-tutorial-with-example/
DMCA.com