Java Servlet Programming and application of the second

Source: Internet
Author: User
Tags contains html page netscape web server client microsoft iis


The development environment required to write a servlet



The basic environment required for servlet development is JSDK and a Web server that supports the servlet.



1.JSDK (Java Servlet Development Kit)



JSDK contains the Java class libraries and related documentation needed to compile the servlet application. For users who are developing with Java 1.1, JSDK must be installed. JSDK has been integrated into the Java 1.2 beta, and if you are developing with Java 1.2 or later, you do not have to install JSDK.



JSDK can be downloaded at JavaSoft Company's site for free, with the address: http://www.sun.com/software/jwebserver/redirect.html



2. Web server with servlet support



The servlet needs to run on a Web server that supports a servlet. The Web server that currently supports the servlet, JSWDK1.0.1 of Sun Corporation. If the existing Web server does not support a servlet, you can leverage the server additions (add-ons) of some third-party vendors to enable the Web server to support the servlet, which is the Live software company (http:// Www.livesoftware.com provides a product called JRun that enables Microsoft IIS and Netscape Web server to support the servlet by installing the appropriate version of JRun.



The process of developing a servlet



Here's a simple servlet example to illustrate the process of developing a servlet.



1. Writing servlet code



The Java Servlet API is a standard Java Extender package that contains two Package:javax.servlet and Javax.servlet.http. For developers who want to develop custom based protocols, the classes and interfaces in the Javax.servlet package should be used, and developers interacting with the client only with HTTP protocols need to be developed using the classes and interfaces in the Javax.servlet.http package.



The following is a servlet's program code (REQUESTINFOEXAMPLE.JAVA):


Import java.io.*;
Import java.servlet.*;
Import javax.servlet.*;
public class Requestinfoexample extends HttpServlet {
public void doget (HttpServletRequest request, httpservletresponse response)
Throws IOException, Servletexception
{
Response.setcontenttype ("text/html");
PrintWriter out = Response.getwriter ();
Out.println ("");
Out.println ("");
Out.println ("");
Out.println ("Request information Example");
Out.println ("");
Out.println ("");
Out.println ("

Request information Example

");
Out.println ("Method:" + Request.getmethod ());
Out.println ("Request URI:" + Request.getrequesturi ());
Out.println ("Protocol:" + request.getprotocol ());
Out.println ("PathInfo:" + request.getpathinfo ());
Out.println ("Remote Address:" + request.getremoteaddr ());
Out.println ("");
Out.println ("");
}
public void DoPost (HttpServletRequest request, HttpServletResponse Res)
Throws IOException, Servletexception
{
Doget (request, response);
}
}


The servlet implements the following functionality: When a user accesses the servlet through a browser, the servlet returns an HTML page to the client browser:




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.