0
点赞
收藏
分享

微信扫一扫

IntelliJ IDEA(2019)之Web项目创建


文章目录

  • ​​一、创建web项目​​
  • ​​二、tomcat项目部署​​
  • ​​三、创建servlet​​


  上篇文章介绍了idea的安装及普通java项目的使用,本文来介绍下web项目的创建及相关操作

一、创建web项目

1、打开idea软件,点击界面上的Create New Project

IntelliJ IDEA(2019)之Web项目创建_idea

2、进入如下界面。选中 java Enterprise,配置jdk,tomcat,勾选Web Application案例,注意勾选生成web.xml文件

IntelliJ IDEA(2019)之Web项目创建_tomcat_02


IntelliJ IDEA(2019)之Web项目创建_web项目_03

IntelliJ IDEA(2019)之Web项目创建_2019_04

3、指定项目的名称及项目文件的保存地址

IntelliJ IDEA(2019)之Web项目创建_idea_05

4、创建成功

IntelliJ IDEA(2019)之Web项目创建_web项目_06

5、创建class文件和lib文件夹
  点击项目的WEF-INF文件夹 ,右键,New → Directory 创建两个文件夹,classes(用来存放编译后输出的class文件) 和 lib(用于存放第三方jar包)

IntelliJ IDEA(2019)之Web项目创建_servlet_07

IntelliJ IDEA(2019)之Web项目创建_web项目_08

6、配置classes文件夹路径
   File → 选择 Project Structure → 选择 Module → 选择Paths → 选择 “Use module compile output path” -> 将Output path和Test output path都选择刚刚创建的classes文件夹。

IntelliJ IDEA(2019)之Web项目创建_servlet_09

IntelliJ IDEA(2019)之Web项目创建_servlet_10

7、配置lib文件夹路径
  点击Paths旁边的Dependencies 点击右边的”+”号 → 选择”Jars or Directories” -> 将Output path和Test output path都选择刚刚创建的classes文件夹 → 选择”Jar Directory” 然后一路OK就行了.

IntelliJ IDEA(2019)之Web项目创建_idea_11

选择刚刚创建的lib文件夹

IntelliJ IDEA(2019)之Web项目创建_servlet_12

IntelliJ IDEA(2019)之Web项目创建_servlet_13

二、tomcat项目部署

1.配置tomcat
  点击Run ,选择Edit Configurations.

IntelliJ IDEA(2019)之Web项目创建_tomcat_14

IntelliJ IDEA(2019)之Web项目创建_web项目_15

点击右上角的三角形,运行

IntelliJ IDEA(2019)之Web项目创建_servlet_16

IntelliJ IDEA(2019)之Web项目创建_tomcat_17

三、创建servlet

  src–>New–>Create New Servlet

IntelliJ IDEA(2019)之Web项目创建_idea_18

IntelliJ IDEA(2019)之Web项目创建_idea_19

servlet中简单代码

/**
* 通过urlPatterns指定映射地址或者在web.xml文件中配置
*/
@WebServlet(name = "helloServlet",urlPatterns = {"/hello"})
public class HelloServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("hello serlvet");
request.getRequestDispatcher("/index.jsp").forward(request,response);
}
}

3.测试
  运行tomcat访问测试:​​​http://localhost:8080/hello​​

IntelliJ IDEA(2019)之Web项目创建_servlet_20

IntelliJ IDEA(2019)之Web项目创建_idea_21

访问成功~到此idea中创建web项目搞定


举报

相关推荐

0 条评论