001-web基本程序搭建
一、IDEA创建项目
1、基本项目创建
1.1、基本步骤
1、Create New Project 【File→New→Project】→New Project
2、maven→group、artifactId、version即可
1.2、调整maven配置
1、统一源代码编码方式
在pom中添加
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
2、统一源代码与编译输出JDK版本
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
maven中心仓库地址:http://search.maven.org/
3、打包时忽略测试
<!-- Test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
基本项目创建完毕
2、转为java web项目
2.1、转化步骤
a.在main下添加webapp目录
b.在webapp下添加WEB-INF目录
c.在WEB-INF下添加web.xml文件
此时IDEA会出现

自动识别项目为web【即Servlet框架】项目,点击Configure,在点击ok即可
在web.xml中添加如下,使用servlet 3.0
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
2.2、添加javaweb的maven依赖
1、打包设置【pom中】
<packaging>war</packaging>
2、添加java web 所需依赖Servlet 、JSP、JSTL等
<dependencies>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- JSP -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
3、增加tomcat插件
<!-- Tomcat -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.artifactId}</path>
</configuration>
</plugin>
至此java web搭建完毕
3、简单web应用【原生】
需求:写一个HelloServlet,接收Get类型的/hello请求,转发到/WEB-INF/jsp/hello.jsp页面,在hello.jsp页面上显示当前时间。
3.1、编写Servlet类
package com.lhx.chapter1; 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;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date; /**
* @author lihongxu6
* @since 2017/10/9 14:07
*/
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentTime = dateFormat.format(new Date());
req.setAttribute("currentTime", currentTime);
req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req, resp);
}
}
说明:使用WebServlet注解并配置请求路径,对外发布Servlet服务。
Servlet 3.0增加WebServlet配置后,在web.xml不用配置即可
3.2、编写jsp页面
在WEB-INF下建立jsp文件夹,下建立hello.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Hello!</h1>
<h2>当前时间是:${currentTime}</h2>
</body>
</html>
至此以编写完成
4、web启动
方式一、使用集成的tomcat
http://www.cnblogs.com/bjlhx/p/7059671.html
方式二、使用tomcat的maven插件
在pom中增加如下
<!-- Tomcat -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.artifactId}</path>
</configuration>
</plugin>
打开IDEA的maven面板,双击tomcat7:run命令即可。

访问此地址Running war on http://localhost:8080/lhx-chapter1/hello即可
以Debug方式访问

添加一个maven方式的Configuration配置
1、打开 Edit Configuration配置,找到maven
2、名称输入tomcat,Command Line输入:tomcat7:run即可
5、git的使用
5.1、编写.gitignore文件
在根目录下增加.gitignore文件
# Maven #
target/
# IDEA #
.idea/
*.iml
# Eclipse #
.settings/
.metadata/
.classpath
.project
Servers/
5.2、提交本地git
在VCS中”Import into Version Control/Create Git Repository... “,点击ok,即创建本地仓库完成。
选中项目,右键→git→add将添加至本地仓库
选中项目,右键→git→Commit Directory...将添加至本地仓库
git add负责将文件内容存入blob对象,并更新index,git commit负责根据index生成tree对象,然后生成commit对象指向这个tree对象。
5.3、推送至远程git
可以使用开源的Github或者开源中国http://git.oschina.net,建立项目
本地使用
git remote add origin < Git仓库地址>
git push -u origin master
001-web基本程序搭建的更多相关文章
- 简单java web应用程序搭建与部署
1. 准备工作 工具:tomcat.editplus.jdk.windows操作系统 操作:在windows操作系统上安装jdk.tomcat.editplus,配置JAVA_HOME,Path,CL ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(任务管理系统)-2项目搭建
系统要求 首先建议采用 Windows 10 专业版/企业版/教育版,且必须是64位操作系统,原因是docker装起来比较方便,Win7装起来比较麻烦,且不确定是否有其他问题(自己没有实践过) 其次W ...
- 基于EasyUI的Web应用程序及过去一年的总结
前言 在这家公司服务了一年时间,一个多月之前已经提交了离职申请,好在领导都已经批准了,过几天就办理手续了,在此感谢领导的栽培与挽留,感谢各位同事在工作中的给我的帮助,感谢师傅(在我心中当他是我师傅,跟 ...
- ASP.NET MVC3入门教程之第一个WEB应用程序
本文转载自:http://www.youarebug.com/forum.php?mod=viewthread&tid=91&extra=page%3D1 上一节,我们已经搭建好了AS ...
- Node.js高级编程读书笔记 - 4 构建Web应用程序
Outline 5 构建Web应用程序 5.1 构建和使用HTTP中间件 5.2 用Express.js创建Web应用程序 5.3 使用Socket.IO创建通用的实时Web应用程序 5 构建Web应 ...
- CentOS下Web服务器环境搭建LNMP一键安装包
CentOS下Web服务器环境搭建LNMP一键安装包 时间:2014-09-04 00:50来源:osyunwei.com 作者:osyunwei.com 举报 点击:3797次 最新版本:lnmp- ...
- 一步一步学习SignalR进行实时通信_9_托管在非Web应用程序
原文:一步一步学习SignalR进行实时通信_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信\_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信_9_托管在非We ...
- office web apps 部署-搭建office web apps服务器
二.搭建office web apps服务器 相关文件可以去焰尾迭分享的百度网盘下载,下载地址:http://pan.baidu.com/s/1o6tCo8y#path=%252Foffice%252 ...
- (译)Web是如何工作的(2):客户端-服务器模型,以及Web应用程序的结构
原文地址:https://medium.freecodecamp.org/how-the-web-works-part-ii-client-server-model-the-structure-of- ...
- 03、NetCore2.0下Web应用之搭建最小框架
03.NetCore2.0下Web应用之搭建最小框架 这里我们不使用VS2017或者CLI命令的方式创建Asp.Net Core 2.0网页应用程序,而是完全手工的一点点搭建一个Web框架,以便更好的 ...
随机推荐
- Atitit.创建快捷方式 windows快捷方式的原理
Atitit.创建快捷方式 windows快捷方式的原理 1. Windows中有2种快捷方式的文件:1 2. Jshortcut2 2.1. 提示新不上jshortcut.dll2 2.2. 使用w ...
- 怎样启动JDBC Debug模式,打印JDBC诊断日志
1.下载Debug版本号jar包 首先要下载一个Debug版本号的JDBC jar包,Debug版本号的jar包命名形式为jdbcX_g.jar(例如以下图所看到的).如Oracle11g的 ...
- Visual Studio - 引入动态库
以VS2013为例: 1.新建项目 2.选择"Win32控制台应用程序",点确定 勾选“控制台应用程序”和“空项目”选项,点击完成,然后新建一个C文件,在文件头上右键: 3.粘贴准 ...
- apache下用expires_module让浏览器缓存静态文件
让浏览器缓存CSS.JS.图片.静态文件等是很重要的事情,这样可以减轻服务器的压力,省的浏览器经常要去服务端下载这些静态文件.下面看看配置方法吧. 1.开启apache扩展模块mod_expires. ...
- SQL中使用视图的优点和缺点是什么
视图的优点与缺点 在程序设计的时候必须先了解视图的优缺点,这样可以扬长避短,视图具有如下的一些优点: ● 简单性.视图不仅可以简化用户对数据的理解,也可以简化他们的操作.那些被经常使用的查询可以被定义 ...
- 在linux下使用curl
使用curl从 ftp下载文件 curl ftp://192.168.31.164/lrzsz-0.12.20.tar.gz --user root:123456 -o lrzsz-0.12.20.t ...
- flex初始化方法
initalize是初始化,creationcomplete是创建完成,applicationComplete是应用程序中所有的实例都创建完成后才执行,三者的执行顺序是intalize creatio ...
- apple touch icon 大小总结
<!-- For Chrome for Android: --> <link rel="icon" sizes="192x192" href= ...
- Cocos2dx的ClippingNode裁剪节点使用方式
1.http://shahdza.blog.51cto.com/2410787/1561937 2.http://www.firedragonpzy.com.cn/index.php/archives ...
- chrono
时间段的表示 tmplate<class Rep,class Period=ratio<1>> class duration; duration类被用来表示时间段的计量器,Re ...