一、bootstrap

本项目采用bootstrap3

bootstrap中文网 https://www.bootcss.com/

使用bootstrap三步:

1.导入jQuery

2.导入bootstrap自己的css样式

3.导入bootstrap自己的js文件

  1. <script type="text/javascript" src="js/jquery-3.2.1.min.js"</script>
  2. <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
  3. <script type="text/javascript" src="bootstrap-3.3.7-dist/js/bootstrap.js"></script>

bootstrap定义了大量的样式库,要使用样式,只要将元素的class指定为样式库中的值。

二、第一个网页

index.jsp

和css等资源文件一起放在web层的webapp下

新建plugin文件夹,bootstrap放在里面

此时启动项目,发现样式不对

F12控制台报错

资源路径进行配置

样式在网页推荐写绝对路径

写监听器

web层创建

编写监听器

  1. package com.atguigu.scw.manager.listener;
  2.  
  3. import javax.servlet.ServletContext;
  4. import javax.servlet.ServletContextEvent;
  5. import javax.servlet.ServletContextListener;
  6.  
  7. /**
  8. * 项目启动时,将一些常用数据放在application域中,大家都能用
  9. * @ClassName MyAppListener
  10. * @Description TODO(这里用一句话描述这个类的作用)
  11. * @version 1.0.0
  12. */
  13. public class MyAppListener implements ServletContextListener{
  14.  
  15. public void contextInitialized(ServletContextEvent sce) {
  16. ServletContext servletContext = sce.getServletContext();
  17. //1.将项目放在application域中
  18. servletContext.setAttribute("ctp", servletContext.getContextPath());
  19.  
  20. }
  21.  
  22. public void contextDestroyed(ServletContextEvent sce) {
  23. //2.项目关闭,销毁application域中所有数据
  24.  
  25. }
  26.  
  27. }

getContextPath()返回站点的根路径,也就是项目的名字 ,比如在web层返回/manager-web

在web.xml中进行配置

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. id="WebApp_ID" version="2.5">
  6.  
  7. <!-- 启动自己的listener -->
  8. <listener>
  9. <listener-class>com.atguigu.scw.manager.listener.MyAppListener</listener-class>
  10. </listener>
  11.  
  12. <!-- 启动spring容器 -->
  13. <!-- needed for ContextLoaderListener -->
  14. <context-param>
  15. <param-name>contextConfigLocation</param-name>
  16. <param-value>classpath:spring-*.xml</param-value>
  17. </context-param>
  18.  
  19. <!-- Bootstraps the root web application context before servlet initialization -->
  20. <listener>
  21. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  22. </listener>
  23.  
  24. <!-- The front controller of this Spring Web application, responsible for
  25. handling all application requests -->
  26. <servlet>
  27. <servlet-name>springDispatcherServlet</servlet-name>
  28. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  29. <init-param>
  30. <param-name>contextConfigLocation</param-name>
  31. <param-value>classpath:springmvc.xml</param-value>
  32. </init-param>
  33. <load-on-startup>1</load-on-startup>
  34. </servlet>
  35.  
  36. <!-- Map all requests to the DispatcherServlet for handling -->
  37. <servlet-mapping>
  38. <servlet-name>springDispatcherServlet</servlet-name>
  39. <url-pattern>/</url-pattern>
  40. </servlet-mapping>
  41.  
  42. <!-- 加上字符编码过滤器 -->
  43. <filter>
  44. <filter-name>CharacterEncodingFilter</filter-name>
  45. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  46. <!-- 只是指定了编码格式 -->
  47. <init-param>
  48. <param-name>encoding</param-name>
  49. <param-value>utf-8</param-value>
  50. </init-param>
  51. <!-- 进行请求乱码解决 -->
  52. <init-param>
  53. <param-name>forceRequestEncoding</param-name>
  54. <param-value>true</param-value>
  55. </init-param>
  56. <init-param>
  57. <param-name>forceResponseEncoding</param-name>
  58. <param-value>true</param-value>
  59. </init-param>
  60. </filter>
  61. <filter-mapping>
  62. <filter-name>CharacterEncodingFilter</filter-name>
  63. <url-pattern>/*</url-pattern>
  64. </filter-mapping>
  65.  
  66. </web-app>

index.jsp中资源的路径都如下面所示,将路径和实际资源位置一一检查

css

js

重新运行

网页显示正常

【JavaWeb项目】一个众筹网站的开发(三)第一个网页的更多相关文章

  1. 【JavaWeb项目】一个众筹网站的开发(五)后台用户登录功能

    用户模块 1)注册 表单校验,使用校验插件 用户密码需要加密存储 注册成功后来到管理控制台,将用户放在session中,防止以后获取 以后用户经常获取用户id,使用mabatis主键自增策略,保存用户 ...

  2. 【JavaWeb项目】一个众筹网站的开发(八)后台页面详细设置

    一.user.jsp改造 删除引入菜单 抽取导航栏 nav-bar.jsp,删除引入导航栏 删除引入main.jsp的到好烂 数据库里添加url 报错,url不对 没有/ url正确 action=& ...

  3. 【JavaWeb项目】一个众筹网站的开发(四)后台用户注册功能

    重点: 密码加密存储 使用jQuery插件做校验和错误提示等 密码不能明文存储,在数据库中是加密存储的 可逆加密:通过密文使用解密算法得到明文 DES AES 不可逆加密:通过密文,得不到明文 MD5 ...

  4. 【JavaWeb项目】一个众筹网站的开发(一)架构搭建

    本项目是@尚硅谷相关视频的记录. 本项目使用Maven构建,工程架构如下图所示: 一.公司的公共父工程和工具类包 1.父工程 每个公司都有自己的父工程 父工程作用:对公司使用的jar包进行统一管理,别 ...

  5. 【JavaWeb项目】一个众筹网站的开发(九)邮件开发

    Java官方支持邮件开发,Javax-mail jdk中默认没有,需要另外下载 apache的基于Javax-mail开发了commons-mail,更加简单高效,推荐使用 一.电子邮件接收和发送协议 ...

  6. 【JavaWeb项目】一个众筹网站的开发(六)后台用户权限控制

    登陆成功进入控制面板后 左侧的菜单是共同的元素,抽取出来做静态包含 要求必须是按照不同的用户得到不同的菜单 用户做了权限限制,哪个用户能操作哪些内容(链接.按钮.内容) 一.RBAC权限模型 权限管理 ...

  7. 【JavaWeb项目】一个众筹网站的开发(二)架构搭建之架构测试

    1.dao层和pojo都是使用mbg生成,基本的CRUD以及JavaBean 2.将mbg放在dao层,一旦dao层打包以后mbg就删除掉 一.创建数据库用于测试 数据库名称:scw_0325 SQL ...

  8. 【JavaWeb项目】一个众筹网站的开发(七)后台用户菜单

    mvn命令不能运行: jar-war-pom之间是可以直接写,优先找这个工程,而不是仓库的位置 pom-pom子父关系,需要去仓库中找,我们需要使用<relativePath>../pro ...

  9. JavaWeb项目:旅游网站【涉及各种知识】

    JQuery异步请求(ajax) $.ajax({ // 请求方式为get或者post等 type: "GET", // 服务器响应的数据类型 dataType: "js ...

随机推荐

  1. Ubuntu Visual code安装与使用

    1.直接启动软件中心,输入visual studio code,点击install即可,千万千万不要去装逼搞什么linux指令安装,死都不知道怎么死的 2.Visual code是以文件夹为工程目录的 ...

  2. .NET Core 构建跨平台的桌面应用

    1.运行环境 开发工具:Visual Studio 2017 JDK版本:.NET Core 2.0 项目管理工具:nuget 2.GITHUB地址 https://github.com/nbfujx ...

  3. ldd3 第12章 PCI驱动程序

    PCI接口 PCI寻址 引导阶段 配置寄存器和初始化 MODULE_DEVICE_TABLE 注册PCI驱动程序 佬式PCI探测 激活PCI设备 访问配置空间 访问I/O和内存空间 PCI中断 硬件抽 ...

  4. window 安装VisualSvn Server

    VisualSvn Server 1 .VisualSvn Server  介绍和下载 VisualSvn Server是免费的,而VisualSvn是收费的.VisualSvn是Svn的客户端,和V ...

  5. 22 October in 614

    Contest A. defile struct 自定义排序.按照题意抽象成模型模拟就可以了. 自定义排序核心代码: struct node { int x, id; } d[1000003]; bo ...

  6. HashMap存取原理之JDK8

    前言 哈希表(hash table)也叫散列表,是一种非常重要的数据结构 应用场景之一:缓存技术(比如memcached的核心其实就是在内存中维护一张大的哈希表) 目录 一.哈希表 二.hashmap ...

  7. 高并发大流量专题---5、CDN加速

    高并发大流量专题---5.CDN加速 一.总结 一句话总结: CDN就是多整几台节点服务器,选距离用户最近的服务器来给用户服务,实现的话可以用阿里云.腾讯云他们提供的功能,简单方便,妈妈再也不用担心我 ...

  8. 解决“/bin/bash^M: bad interpreter: No such file or directory”

    在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识.  查看脚本文件是dos格式还是unix格式的几种办 ...

  9. webpack请求文件路径代理

    在开发模式下,访问页面请求会跑到根路径,因为写的都  ./images  而index又在根目录, 所以访问地址会是 http://localhost:8080/images/abc.jpg  而实际 ...

  10. CSS中让背景图片居中且不平铺

    background:url(../images/logo.jpg) no-repeat center ;