>>>PREVIOUS>>>
Servlets
Servlets are small programs that execute on the server side of a Web connection, used to extend the functionality of a Web Server.
JSDK
Java Servlet Development Kit (JSDK) contains class libraries to create servlets. It contains the utility servletrunner to test the servlets. The basic life cycles of servlets are init( ), service( ) and destroy( ).
The steps to create a servlets areServlets are small programs that execute on the server side of a Web connection, used to extend the functionality of a Web Server.
JSDK
Java Servlet Development Kit (JSDK) contains class libraries to create servlets. It contains the utility servletrunner to test the servlets. The basic life cycles of servlets are init( ), service( ) and destroy( ).
Create and compile the servlet source code.
Start the servletrunner utility.
Start a Web browser and reuest the servlet.
Adv of servlets over CGI :
Performance is better. Creating a separate process to handle each client reuest isn't necessry.
Servlets are platform-independent, because they are written in Java.
The Java Security Manager on the server enforces a set of restrictions to protect the resources on a server machine.
The full functionality of Java class is available to the servlet. It can communicate with applets, databases or other software via sockets and RMI.
Example :
Step 1 : colorGet.html
Step 2 :
colorGetSelvlet.java
import java.io.* ;
import javax.servlet.*;
import javax.servlet.http.*;
public class colorGetServlet extends HttpServlet
{
public void doGet (HttpServlet request, HttpServletResponse response)
throws ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter( );
pw.println(" The selected color is : " );
pw.println(color);
pw.close( );
}
}
Step 3: compile the above program colorGetServlet.java
Step 4 : start servlet runner by c:\javawebbrowser2.0\jserv
Step 5: Display the web page in the browser. Select a color and submit.
import javax.servlet.*;
import javax.servlet.http.*;
public class colorGetServlet extends HttpServlet
{
public void doGet (HttpServlet request, HttpServletResponse response)
throws ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter( );
pw.println(" The selected color is : " );
pw.println(color);
pw.close( );
}
}
Step 3: compile the above program colorGetServlet.java
Step 4 : start servlet runner by c:\javawebbrowser2.0\jserv
Step 5: Display the web page in the browser. Select a color and submit.
>>>NEXT>>>
No comments:
Post a Comment