3

java web开发(maven创建servlet程序)

 1 year ago
source link: https://blog.csdn.net/feixiaoxing/article/details/127139667
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

java web开发(maven创建servlet程序)

嵌入式-老费 已于 2022-10-02 08:27:39 修改 48

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

        之前我们写了一篇文章,主要是说一般情况下怎么开发servlet。其实,用maven创建servlet工程也是非常方便的。网上有一篇文章,地址在这,https://www.cnblogs.com/happy-lin/p/14977176.html,也谈到了怎么实现idea+maven+servlet的工程开发。有部分内容借鉴了一下,大家可以一步一步尝试下。

1、首先利用maven创建webapp,注意一定选择maven-archetype-webapp

e0e4f335b6c34b75903a322e402200cd.png

2、不妨将工程命名为Hello,等工程创建好后,创建源码目录,默认是没有的,一般放在main下面,目录名叫java

03724c6fa968435a98e53aec071634f2.png

3、在java目录中添加MyServlet.java代码,



newCodeMoreWhite.png

4、在pom.xml文件添加必要的dependency依赖

5、修改web.xml文件

6、重新将jsp文件命名为index.jsp,调整一下内容,



newCodeMoreWhite.png

7、开始tomcat配置,

7.1 配置server目录和端口

068c5ee6730c4964b7dcbb1d7e913b47.png

 7.2 配置tomcat部署

4e820aacbfc84da3892afdfd70073ba6.png

8、启动调试tomcat

        配置好tomcat后,就可以在右侧看到绿色的按钮,单击后就可以启动tomcat,

        输入localhost:8090/Hello_war_exploded/就可以看到这个内容,

     welcome to learn java,come on ~

         输入localhost:8090/Hello_war_exploded/demo可以看到这个内容,

my first servlet code

        正常情况下,看到上面这些内容,就代表用maven创建的servlet代码已经成功跑起来了。

        如果编译的过程中有问题,只需要用maven更新一下依赖即可,问题不是很大。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK