使用idea創建web項目

一、創建web項目

1、打開idea軟件,點擊界面上的Create New Project

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

3、指定項目的名稱及項目文件的保存地址

4、創建成功

5、創建class文件和lib文件夾   點擊項目的WEF-INF文件夾 ,右鍵,New → Directory 創建兩個文件夾,classes(用來存放編譯後輸出的class文件) 和 lib(用於存放第三方jar包)

6、配置classes文件夾路徑    File → 選擇 Project Structure → 選擇 Module → 選擇Paths → 選擇 “Use module compile output path” -> 將Output path和Test output path都選擇剛剛創建的classes文件夾。

7、配置lib文件夾路徑   點擊Paths旁邊的Dependencies 點擊右邊的”+”號 → 選擇”Jars or Directories” -> 將Output path和Test output path都選擇剛剛創建的classes文件夾 → 選擇”Jar Directory” 然後一路OK就行了.

選擇剛剛創建的lib文件夾

二、tomcat項目部署

1.配置tomcat   點擊Run ,選擇Edit Configurations.

點擊右上角的三角形,運行

三、創建servlet

  src–>New–>Create New Servlet

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

訪問成功~到此idea中創建web項目搞定

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章