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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


selvakumar
code
1 Answer(s)      5 years and 6 months ago
Posted in : Servlet Interview Questions



Advertisement
View Answers

July 11, 2009 at 2:38 PM


Hi Friend,

Servlet service() method:

Once the servlet starts getting the requests, the service() method is called by the servlet container to respond. The servlet services the client's request with the help of two objects. These two objects javax.servlet.ServletRequest and javax.servlet.ServletResponse are passed by the servlet container.

The status code of the response always should be set for a servlet that throws or sends an error.

Parameters - The service() method takes the ServletRequest object that contains the client's request and the object ServletResponse contains the servlet's response. The service() method throws ServletException and IOExceptions exception.

Example:

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

public class HelloWorldExample extends HttpServlet {
public void service(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
Date today = new Date();
out.println("<html>"+"<body><h1>Today Date is</h1>");
out.println("<b>"+ today+"</b></body>"+ "</html>");
}
}

In web.xml:

<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/HelloWorldExample</url-pattern>
</servlet-mapping>

Thanks


Related Tutorials/Questions & Answers:
code
code  code for android sample program
code
code    how to write this in java
Advertisements
Code
Code  code for connecting c lang to database
code for this is
code for this is  a b c d c b a a b c c b a a b b a a a code
code
code  please provide code for custom tags.by using currdate tag we need to get current date?please give me code
code
code   hi I need help in creating a java code that reminds user on a particular date about their festival. i have no clue of how to do it.. am looking forward to seek help from you
code
the correct code for a program.The output of the program is listed below...: {Block 5} ADDRESS-3: {San Juan} POST CODE:{6745} ENTER CODE (XX TO stop) CODE:{FF1} QUANTITY:{2} CODE:{TR4} QUANTITY:{1} CODE:XX INVOICE FOR YOUR ORDER Harry
code
code to create the RMI client on the local machine: import java.rmi.*; public... : "+e); } } } However, when the preceding code is executed it results... the correct code
code
code  i have four textboxes.whenever i click on up,down,left or down arrows then the cursor move to another textbox based on the key pressed.i want code for this in javascript
code
line of code to print the amount he should be paid as allowance
code
code  write a program to encrypt and decrypt the cipher text "adfgvx"   Hi Friend, Try the following code: import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; import java.io.
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
Source code
Source code  source code of html to create a user login page
c code
c code  c code for this formula x=(y-0.22z-072)4; where y=7.32 x=3.1 then ans x=23.9 end code for this   c code for this formula x=(y-0.22z-072)4; where y=7.32 x=3.1 then ans x=23.9 can any one end code
jsp code
jsp code  what are the jsp code for view page in online journal
stegnography code
stegnography code  code for the digital stegnographic technique for the encryption and decryption of image
example code
example code  code for displaying a list from another class on a midlet
Code for a triangle.....
Code for a triangle.....   1 1 5 1 1 5 25 5 1 What is the source Code for above output
c code
c code  c code for this formula x=(y-0.22z-072)4; where y=7.32 x=3.1 then ans x=23.9 end code
JSF code
need jsf code that will populate combo box values from the database  Hi, i'm new on JSf,I need jsf code that will populate combo box values from the database when the form runs
Code for Pattern
Code for Pattern   * *** * * Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
Code for Pattern
Code for Pattern   * * * * * * * * Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
Code for Pattern
Code for Pattern   * * * * * * * * * * * Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
JAVA CODE
JAVA CODE  JAVA SOURCE CODE TO BLOCK A PARTICULAR WEB SITES(SOCIAL WEB SITE
java code
java code  write a java code to convert hindi to english using arrays
jsp code
jsp code  i want health management system project code using jsp.its urgent
Advertisements
 

 

 

DMCA.com