The most annoying part of my learning about JAVA is the configuration of various development tools. Today I will introduce the configuration of servlet IN THE NEXT jsp (first choice for SUN enterprise-level applications.
Use the editplus + tomcat tool (a good JSP running platform)
To run Servlet, jsp (the first choice for SUN enterprise-level applications)/Servlet container is required. I recommend that you use tomcat (a useful JSP running platform) for beginners ).
Tomcat (a very useful JSP operating platform) (the latest version 5.0): http://cvs.apache (Unix platform most popular WEB server platform ). org/builds/jakarta-tomcat (a very useful JSP operating platform)-5/nightly/jakarta-tomcat(a very useful jspoperating platform -5-bin-20030725.zip
Decompress the package:
C: omcat (a good JSP running platform)
Then configure the environment variables. Add three system variables:
JAVA_HOME: C: JDK
Tomcat (a very useful JSP running platform) _ HOME: C: omcat (a very useful JSP running platform)
CLASSPATH: % JAVA_HOME % lib; % tomcat (a good JSP running platform) _ HOME % lib
The environment variables of tomcat (a very useful JSP running platform) are configured. The following checks whether tomcat (a very useful JSP running platform) can run:
In the console, go to the C: omcat (a very useful JSP running platform) in directory, run startup, and then return to a window to jump to a bunch of things, the Server is running.
Enter http: // localhost: 8080 in the browser. If the welcome page appears, it means tomcat (a very useful JSP running platform) is okay. Write your first Servlet as above.
Import java. io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class HelloWorld extends HttpServlet
{
Public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Response. setContentType ("text/html ");
PrintWriter out = response. getWriter ();
Out. println ("Out. println ("This is my first Servlet ");
Out. println ("</title> Out. println ("Out. println ("</body>
}
}
Then use javac HelloWorld. java to compile the file. If the file cannot be imported javax. servlet .*
Then we should copy the servlet. jar file in C: omcat (a very useful JSP running platform) commonlib to C: JDKjrelibext and compile it again, so there is no problem!
Then, in the C: omcat (a very useful JSP running platform) Directory of tomcat (a very useful JSP running platform), The web‑root file structure is as follows:
ROOTindex.html
ROOTwelcom. jsp (preferred for SUN Enterprise applications)
ROOTWEB-INFlibMyServlet.jar (If your servlet. class is typed into a. jar file, put it under lib)
ROOTWEB-INFclassesHelloWorld.class (put the HelloWorld. class file generated above in it)
Then, enter http: // localhost: 8080/servlet/HelloWorld in the browser. The Error 404 -- Not Found is returned by the Server.
What's going on?
Servlet must use C: omcat (a very useful JSP running platform. xml (standardization is getting closer and closer) file registration, open this web with EP. add:
<Servlet>
<Servlet-name> HelloWorld </servlet-name>
<Servlet-class> HelloWorld </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-name> HelloWorld </servlet-name>
<Url-pattern>/servlet/helloworld </url-pattern>
</Servlet-mapping>
Such a structure
<Servlet>
<Servlet-name> HelloWorld </servlet-name>
<Servlet-class> HelloWorld </servlet-class>
</Servlet>
Indicates the included servlet class. The following structure:
<Servlet-mapping>
<Servlet-name> HelloWorld </servlet-name>
<Url-pattern>/servlet/HelloWorld </url-pattern>
</Servlet-mapping>
Specifies the URL mode to which HelloServlet maps.
After modifying web. xml (standardization is getting closer and closer), restart the Server and then input http: // localhost: 8080/servlet/HelloWorld. Then, there is a big Hello, World! Waiting for you.
Finally, let's talk about how to package.
Because there are many servers, We need to package the developed jsp (the preferred choice for SUN enterprise-level applications) for use with any server.
JAR command I used
Specifically: jar cvf Myjsp (preferred for SUN Enterprise Applications )*. * Note: Myjsp (the preferred choice for SUN Enterprise Applications) is the jsp project you created (the preferred choice for SUN Enterprise applications.
In this way, your jsp project (the first choice for SUN Enterprise Applications) can be moved everywhere. For example, tomcat (a very useful JSP running platform) can be developed and applied directly under WEVLOGIC.