jsp/servlet环境搭建

手动配置servlet开发环境:

1. eclipse、tomcat、jdk下载安装;

2. eclipse新建项目,项目依赖tomcat的jar包(包含tomcat和servlet相关jar包)以及jdk等基础jar包,工程目录下新建webapp文件夹,内建WEB-INF文件夹;

  ps:webapp文件夹非必要,可另建其它目录作为应用目录,但是应用目录下必须有WEB-INF文件夹。

3. WEB-INF文件夹内建classes目录、lib文件夹、视图目录和web.xml文件,指定编译文件输入路径到classes目录,web.xml为servlet核心配置文件;

4. web.xml里配置新增的servlet,格式如下:

  <servlet>
    <servlet-name>productServlet</servlet-name>
    <servlet-class>com.google.web.servlet.ProductServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>productServlet</servlet-name>
    <url-pattern>/product</url-pattern>
  </servlet-mapping>

5. servlet3.0可用@WebServlet("/product")注解替代上述配置;

6. 至此,一个简单的servlet配置完成,可通过 http://localhost:8080/product 访问productServlet。

  ps:具体接口地址视tomcat端口应用等配置而定。

  

原文地址:https://www.cnblogs.com/tarencez/p/6359941.html