日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

IDEA創(chuàng)建Maven項(xiàng)目

 印度阿三17 2021-03-07

前言

一些小問題:
關(guān)于maven無(wú)法創(chuàng)建servlet可以點(diǎn)擊查看:《idea 的maven無(wú)法創(chuàng)建servlet》


先創(chuàng)建一個(gè)maven工程,流程如下:

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
以上maven工程創(chuàng)建完成了。

Maven使用入門,小案例

  1. 按照以上步驟,創(chuàng)建的maven工程,結(jié)構(gòu)如下:
    在這里插入圖片描述

  2. maven目錄結(jié)構(gòu)里面缺少了Java源文件夾,需要我們手動(dòng)添加上去,過程如下:

    先新建目錄


    在這里插入圖片描述

在這里插入圖片描述
3.再將新建的文件設(shè)置為源文件
在這里插入圖片描述
4.在java新建包,再在包里新建一個(gè)servlet,關(guān)于maven無(wú)法創(chuàng)建servlet,可以參考前言里的解決辦法進(jìn)行相應(yīng)設(shè)置,

項(xiàng)目的結(jié)構(gòu)如圖:
在這里插入圖片描述
servlet代碼如下:

package aa.bb;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/testServlet")
public class TestServlet extends HttpServlet {protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.getRequestDispatcher("/test.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {doPost(request, response);
    }
}

jsp代碼如下:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
hello!!!Maven
</body>
</html>

pom.xml配置

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven./POM/4.0.0" xmlns:xsi="http://www./2001/XMLSchema-instance" xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>

  <name>maven1</name>
  <groupId>org.example</groupId>
  <artifactId>maven1</artifactId>
  <version>1.0-SNAPSHOT</version>

  <!--放置的都是項(xiàng)目運(yùn)行所依賴的jar包-->
  <dependencies>
<!--    <dependency>-->
<!--      <groupId>javax.servlet</groupId>-->
<!--      <artifactId>servlet-api</artifactId>-->
<!--      <version>2.5</version>-->
<!--      <scope>provided</scope>-->
<!--    </dependency>-->
    <!--jsp-->
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.2</version>
      <scope>provided</scope>
    </dependency>
    <!--junit-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!--servlrt-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <!--配置tomcat-->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <port>8089</port>
        </configuration>
      </plugin>
      <!--配置jdk-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <target>1.8</target>
          <source>1.8</source>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

在這里插入圖片描述
運(yùn)行結(jié)果:

在這里插入圖片描述

在這里插入圖片描述

來(lái)源:https://www./content-4-882551.html

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多