Questions about the Java servlet compilation

Source: Internet
Author: User

Servlet(Server Applet), full nameJava Servlet, no Chinese translation is available. is to useJAvawritten byServerEndprogram. Its main function is to interactively browse and modify data, generate dynamicWebcontent. The narrow servlet refers to the Java language implementation of aInterface, a generalized servlet refers to any class that implements the Servlet interface ., it is generally understood that the servlet is the latter.

The servlet runs in a Java-enabled application server. From the implementation, the servlet can respond to any type of request, but in most cases the servlet is used only to extend the HTTP protocol-based Web server.

Once we know the servlet, we can write a servlet of our own:

File name is Servlettest.java:

import javax.servlet.*;   import javax.servlet.http.*;   import  java.io.*;   import java.util.*;   public class servlettest  Extends httpservlet{  private static final string content_type = "text/ HTML; CHARSET = GBK ";    public void init ()  throws  Servletexception{  }  public void doget (Httpservletrequest request, Httpservletresponse response)  throws ServletException,IOException{   Response.setcontenttype (Content_Type);    printwriter out= response.getwriter ();   out.println ("");   out.println ("");   out.println ("");   out.println (" This is the GET request in response to the servlet ");   out.println (" ");   out.println (" ");   out.close ();  }   public void dopost (httpservletreqUest request,httpservletresponse response)  throws ServletException,IOException{   response.setcontenttype (Content_Type);   printwriter out= response.getwriter ();   out.println ("");   out.println ("");   out.println ("");   out.println (" This is the response to the servlet's post request ");   out.println (" ");   out.println (" ");   out.close ();  }  public void destroy () {  } }

 use CMD to compile him into the Servlettest.class class (where it is important to note that we compile directly when theJava servlet program does not exist in the Compile Times error packet Javax.servlet ) How to solve it?

Locate the installation path for Tomcat, such as C:\Program files\apache-tomcat-8.0.0-rc5\l servlet-api.jarf copy to C:\ProgramFiles\ Java\jdk1.7.0_45\jre\lib\ext is your JDK installation path under the same directory (with the same) and then compile on the OK!


Questions about the Java servlet compilation

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.