最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用IDEA創(chuàng)建Servlet程序的詳細(xì)步驟

 更新時間:2024年08月16日 12:29:57   作者:程序員-小李  
在學(xué)習(xí)servlet過程中,參考的教程是用eclipse完成的,而我在練習(xí)的過程中是使用IDEA的,在創(chuàng)建servlet程序時遇到了挺多困難,在此記錄一下如何用IDEA完整創(chuàng)建一個servlet程序,感興趣的朋友一起看看吧

在學(xué)習(xí)servlet過程中,參考的教程是用eclipse完成的,而我在練習(xí)的過程中是使用IDEA的,在創(chuàng)建servlet程序時遇到了挺多困難,在此記錄一下如何用IDEA完整創(chuàng)建一個servlet程序。

1.打開IDEA,創(chuàng)建一個普通的Java項目

 2.給項目添加Framwork支持

標(biāo)題

可以看到我們的項目多了個web文件夾

 3.配置項目,在WEB-INF下創(chuàng)建兩個文件夾分別是lib,classes,要自己準(zhǔn)備好servlet-api.jar,把它放到lib下,然后打開項目設(shè)置

 打開project structure

 在上面的窗體,繼續(xù)將jar包添加進(jìn)來

 4.編寫servlet程序

 新建一個servlet

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;
/**
 * 簡述:
 *
 * @author:LiYansheng
 * @date:2021/08/11 22:56
 * @version:
 */
@WebServlet(name = "DemoServlet")
public class DemoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //設(shè)置網(wǎng)頁響應(yīng)類型
        response.setContentType("text/html");
        response.getWriter().println("my first servlet code");
    }
}

5.在web.xml中添加映射

<?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_4_0.xsd"
         version="4.0">
    <servlet>
        <servlet-name>DemoServlet</servlet-name>
        <servlet-class>DemoServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>DemoServlet</servlet-name>
        <url-pattern>/demo</url-pattern>
    </servlet-mapping>
</web-app>

 6.運行程序

 點擊這個配置tomcat服務(wù)器

 啟動服務(wù)器

在瀏覽器輸入地址,就可以看到如下內(nèi)容了

 這樣一個Servlet程序就用idea搭建運行出來了

到此這篇關(guān)于使用IDEA創(chuàng)建Servlet程序的詳細(xì)步驟的文章就介紹到這了,更多相關(guān)IDEA創(chuàng)建Servlet程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

建瓯市| 南丰县| 云梦县| 深圳市| 清涧县| 东乌| 新巴尔虎左旗| 中卫市| 开平市| 将乐县| 本溪市| 松滋市| 得荣县| 青岛市| 延边| 株洲市| 永济市| 仁寿县| 林口县| 隆林| 奉新县| 西藏| 满洲里市| 凯里市| 皮山县| 门源| 和田县| 凤冈县| 茌平县| 长丰县| 安福县| 婺源县| 安国市| 疏附县| 庆安县| 南汇区| 贵阳市| 虞城县| 辽源市| 屏边| 南充市|