Servlet简单应用

1.第一步,创建maven程

打开idea,第一次点击create new project

Servlet简单应用

选择MavenServlet简单应用

输入name

Servlet简单应用

打开pom.xml文件,添加依赖

Servlet简单应用

<!--依赖-->
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.3.13</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2.1-b03</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

 第二步,创建module

右键点击SpingMVC工程,new→module,选择Maven,点击next然后输入name。

右键点击servlet模块选择Add Framework Support→Web Application→OK

Servlet简单应用

打开module工程下的pom.xml添加servlet和jsp依赖

Servlet简单应用

 

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2.1-b03</version>
    </dependency>
</dependencies>

第三步,创建servlet

Servlet简单应用

配置servlet

Servlet简单应用创建提交画面jsp

Servlet简单应用 

 

创建跳转画面jsp

Servlet简单应用

  第四步,配置tomcat

1.tomcat下载链接https://tomcat.apache.org/  

Tomcat配置链接https://www.cnblogs.com/KmilyLee/p/9358657.html

打开idea最上面菜单栏run→Edit Configurations,店家左上角的+号 Add New Configuration,选择Tomcat Server →Local6,修改name,点击configuration选择tomcat路径。注意不要选成tomee

Servlet简单应用

 

 点击右下角fix跳转到Deployment窗口。

Servlet简单应用

 

Application context:输入框里的内容是访问路径,不写默认为8080,写了为8080/xxxxxx 

 第五步,启动tomcat

Servlet简单应用

 真实发布网站文件

Servlet简单应用

打开浏览器输入访问路径,成功显示

Servlet简单应用 

请求hello

Servlet简单应用 

Servlet简单应用 

MVC框架做了什么

1.将url映射到java类或java类的方法

2.封装用户提交的数据

3.处理请求--调用相关的业务处理--封装响应数据

4.将相应的数据进行渲染 。jsp /html等表示层数据

上一篇:servlet数据数据通信


下一篇:蓝桥杯真题(python版)(1)不同子串