maven环境配置

#maven系统环境变量配置
1、M2_Home D:\java\apache-maven-3.6.3\bin
2、Maven_Home D:\java\apache-maven-3.6.3

更换使用国内maven库
打开文件下 conf
加速国内的镜像 使用起来更加快
将此镜像转化为

<mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
 </mirror>


更换为

      <id>aliyunmaven</id>
      <mirrorOf>*</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
  </mirror>

#本地仓库

在本地仓库 还有远程仓库

建立一个本地仓库
默认在xml配置文件中的

     | The path to the local repository maven will use to store artifacts.
     |
     | Default: ${user.home}/.m2/repository
    <localRepository>/path/to/local/repo</localRepository>

其中${user.home}为当前用户的文件下 user.m2 其中必须是 点开隐藏的项目才能看的到
如果不去改变就会默认配置到当前 c盘文件下

所以为了 防止我们的c盘被占用掉
使用我们 maven 安装压缩包下 建立一个
创建一个

<localRepository>/path/to/local/repo</localRepository>
改成
<localRepository>D:\java\apache-maven-3.6.3\maven-repo</localRepository>

#idea maven配置

使用搜索搜索maven

在集成环境中 经常使用maven默认的

如果发现问题 就去 maven下进行修改

改成 我们所需要的一些

#maven在idea使用就ok了

使用maven为了使 文件更加完整 需要我们在main文件夹下 加上

java 和resource

使用文件的时候通常 含有 源码目录和

通常标记目录

mark as

​ 1、 Sources root 源码目录

​ 2、Test Source root 测试源码目录

​ 3、resources root 资源目录

​ 4、test Resources test 测试资源目录

#这个是idea中常有的

在代码进行测试的时候通常 是需要改变多个文件夹来准备

在idea中配置tomcat

artified

pom.xml 是maven的核心配置文件

target 目标文件使用maven里面的 clean组件就会让 组件消失

1、maven 版本和头文件


<?xml version="1.0" encoding="UTF-8"?>
<!--Maven版本和头文件-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
<!--这个是我们 刚配置的GAV-->
  <groupId>com.soyadios</groupId>
  <artifactId>javaweb-01-maven</artifactId>
  <version>1.0-SNAPSHOT</version>
<!--
项目打包方式
jar:java应用
war:java web 应用
-->
  <packaging>war</packaging>


<!--配置-->
  <properties>
<!--    项目的默认构建编码-->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>javaweb-01-maven</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

maven的高级之处在于能 帮助 导入jar包所依赖的其它jar包

dependence

资源有资源导出问题

这个问题将会是在未来的编程中显现出来

使用该过滤机制 进行过滤

 <!--在build中配置resources,来防止我们资源导出失败的问题-->
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

#使用javaweb常见的问题

1 maven 版本不够的时候就会 使用降低版本使用

unable to import maven

2、tomcat 闪退

解决方法 使用 startup.bat

tomcat闪退的另一个原因是 Java环境没有配置正确

3、idea中每次都要重复配置maven

在idea中的全局默认配置中去配置

开始的时候使用

4、maven项目中tomcat无法进行配置

5、maven默认环境web项目的中web.xml版本问题

maven仓库的使用

如果没有的话 就是用

https://mvnrepository.com/search?q=HttpServlet

搜索仓库的时候 一般是是按照导入的包的名字去搜索 一般情况下使用最多的人的 一般都是正确的

在使用的方向上来进行 主要的作用域是 scope 这是作用域的意思

头一次使用需要导入多次的包 为了我们方便使用一般是 使用起来多次调用

servlet是由 web服务器调用 web服务器收到客户请求后

浏览器------>---------发送http请求----->web容器 ------->servlet

​ web请求 响应头

​ 请求头和请求体 相应头 响应体

​ 我们编写的实现类处理并请求《--------调用servlet 里面的service方法

1、request会从service拿到请求并且把请i求之后的相应交给response

#mapping问题

1、一个servlet对相应一个指定的映射路径

2、可以使用通配符 *

3、一个servlet可以指定通用的映射路径

4、默认请求路径

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

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
  
</web-app>

#ServletContext

web容器在启动的时候,它会为每个web的每个程序都创建一个对象的servletContext对象,它代表了

servlet 1 servlet2 servlet3 之间进行通信

方法一 :中间通过文件进行第三方进行操作

方法二:ServletContext 可以保存一些东西 三个servlet之间进行获取 servletcontext里面包含的东西 当作

中间件来进行保存

web.xml

<context-param>
    <param-name>url</param-name>
    <param-value>jdbc:mysql://localhost:3306/mybatis</param-value>
</context-param>

servlet:

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServletContext context = this.getServletContext();
    String url =(String)context.getInitParameter("url");
    resp.getWriter().print(url);
}

mvc框架

servlet 和jsp 都可以写java代码 为了易于维护

servlet 专注于 处理请求 以及控制视图跳转

jsp 显示数据

Model 业务处理 :

业务逻辑 (service)

数据持久层 CRUD(Dao)

View

展示数据

提供链接发起Servlet请求(a form image)

control(Servlet)

1、接受用户请求 (req请求参数 Session信息)

2、交给业务成处理对应的代码

3、控制视图的跳转

登录 接受用胡德登录请求 处理用户的请求 获取 用户登录的 参数 username password 交给业务成处理登陆事务 dao层处理事务

Filter

Filter:过滤器

通常

在web 浏览器 发送请求 给web服务器 web服务器加载 过程中需要一层过滤器 增加过滤功能

1、通常中文 会显示乱码

我们可以在配置中加一些内容来对输入输出的内容进行过滤操作

监听器

实现一个监听器接口

常见的应用

GUI编程中 经常使用

用户登录之后才能进入主页 用户注销后 就不能进入主页了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值