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.
Mythree
WEB-INF
Javasource
Classes
Lib
Web.xml
Let servlet.jar in Mythree --- wild
In the eclipe, create a new 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
Inside. (If you don't know how to get, go back to Mars and Pluto.)
In Eclipe, choose "Libraries" on the right side of Mythree - - Properties - Left, select "Libraries" ----- "Add External Jars" enters, select the servlet.jar that just placed under LIB. . . .
Ok, write a class first, take the name: Test
The program code is 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 to
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"
"http://java.sun.com/dtd/web-app_2_3.dtd">
servlet-maping>
web-app>
Please launch your Tomcat again
Enter: 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 ("