Write a servlet project in Notepad

Source: Internet
Author: User

First step: Create a Directory

Create a new folder Firstservlet, and then build two folders under the Firstservlet directory, respectively: Web-inf and SRC. Finally, build a classes folder underneath the Web-inf.

Step Two: Write Sevlet

Under SRC, add a file Helloservlet.java. The code is as follows:

1  PackageCom.firstservlet;2 3 Importjavax.servlet.*;4 Importjavax.servlet.http.*;5 ImportJava.io.*;6 7  Public classHelloServletextendsHttpServlet8 {9      Public voidService (ServletRequest Req,servletresponse resp)throwsservletexception,ioexception{TenResp.getwriter (). Write ("Hello Servlet"); One         } A}

Step three: Compile the Helloservlet.java file

After compiling, the COM folder will appear under the SRC directory and the folder will be moved to the Web-ini>classes directory.

Fourth step: Create Web. xml

Under Web-ini, create a Web. xml file that reads as follows:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Web-appversion= "2.5" 3 xmlns= "Http://java.sun.com/xml/ns/javaee" 4 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" 5 xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee6 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">7  8     <servlet>9         <Servlet-name>HelloServlet</Servlet-name>Ten         <Servlet-class>Com.firstServlet.HelloServlet</Servlet-class> One     </servlet> A     <servlet-mapping> -         <Servlet-name>HelloServlet</Servlet-name> -         <Url-pattern>*.do</Url-pattern> the     </servlet-mapping> - </Web-app>

Fifth Step: Deploy

1. Delete src directory

2. Copy the Firstservlet to Tomcat

3. Access Http://localhost:8080/FirstServlet/HelloServlet.do through the browser

Write a servlet project in Notepad

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.