Article 3: Getting Started with Servlet
Serious warning: People who know the servlet should not look down
Tell me someone to tell you:
Servlet is the server-side Java program
The client is called by the HTTP protocol, forming a dynamic web page at the client
what do you need:
A file: servlet.jar
What, do you ask this JAR file? Use your WinRAR to open it, there is nothing, just to cover the sky .class. Don't take too much. In short, these .class gives you a lot of methods.
Why, did you find this servlet.jar? I don't want to tell you anything, do you do it yourself.
Write a program to see:
Built a project mythree under your Tomcat's WebApps, remember, what else does it need? ! At the same time, I will build a folder in your Mythree, give it a name, just call javasource.
Hurry to put servlet.jar in mythree --- Web-inf --- Lib inside Eclipe, newly build your project, also name mythree, easy to identify, put your source file (.java) In Mythree --- Javasource, put your class file (.class) in Mythree --- Web-INF --- Classes. (If you don't know how to get it, go back to watch Mars and Pluto.) In Eclipe, right-click "Java Build Path" in Eclipe - "Java Build Path" on the right side of "Libraries" ----- "Add External Jars" Enter, select the servlet.jar just placed under LIB. . .
Ok, write a class first, take the name: Test program code as follows: import java.io. *;
Import javax.servlet. *;
Import javax.servlet.http. *;
Public Class Test Extends Httpservlet
{
Public void doget (httpservletRequest RQ,
HTTPSERVLETRESPONSE RP)
THROWS IOEXCEPTION, ServletException
{
Rp.setContentType ("text / html; charSet = GB2312");
PrintWriter out = rp.getwriter ();
Out.println (" Welcome to use servlet html>");
}
}
Change your content of this web.xml XML Version = "1.0" eNCoding = "ISO-8859-1"?>
Please launch your Tomcat again in your IE address bar: http: // localhost: 8080 / mythree / abc
Did you see the effect?
Why, I feel too boring, how is it a little complex?
The procedure just above is:
Import java.io. *;
Import javax.servlet. *;
Import javax.servlet.http. *;
Public Class Test Extends Httpservlet
{
Public void doget (httpservletRequest RQ,
HTTPSERVLETRESPONSE RP)
THROWS IOEXCEPTION, ServletException
{
Rp.setContentType ("text / html; charSet = GB2312");
PrintWriter out = rp.getwriter ();
Out.println ("");
Out.println ("