0


idea中创建jsp项目详细步骤

安装条件:idea软件、tomcat10、jdk11

1、打开idea,在file ->new ->project中新建一个普通的java项目

            ![](https://img-blog.csdnimg.cn/73179281f7bc46d0bd97421b658e9666.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

            ​​​​​​![](https://img-blog.csdnimg.cn/68c047919bb94524b43900e07aa24fe1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

2、在项目名右键Add Framework Support选项中,Web Application上打勾,点击OK。

            ![](https://img-blog.csdnimg.cn/4c61d13a9e9c40cba2da466de3346693.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

3、项目列表->web->WEB-INF,在WEB-INF下新建两个文件夹,分别是classes、lib

            ![](https://img-blog.csdnimg.cn/2b6d48f08b044342aeba4d3bfdd83f68.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/21f1e8273dad440998428c89c0e4384e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_12,color_FFFFFF,t_70,g_se,x_16)![](https://img-blog.csdnimg.cn/f221f3dc0845453292f7226ac95df69f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_12,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/ca1ba68662c5463792afcafe31b6939d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_14,color_FFFFFF,t_70,g_se,x_16)

4、按下ctrl+alt+shift+S,调出Project Structure,选到Modules->Paths,单选框选到Use module compile output path,将两个路径改为刚才创建的classes。

             ![](https://img-blog.csdnimg.cn/9cb8fcdae9f446929cd4e54b9424af0d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

然后选到Dependencies,点击下面的+号,选择jars or dirxxxxxxxx,选择刚创建的lib目录,让选择目录用处的话,选择jar direxxxxxxx,打上勾,点击apply,OK。

            ![](https://img-blog.csdnimg.cn/8cffc176788e496b8b1ab210c4747a61.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_16,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/bb1c643f06bd40e09006dd259209936b.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/5651b4de15e9487682a2ddb31f957c78.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

5、将tomcat/lib目录下的servlet-api.jar复制到我们创建的lib目录里。

            ![](https://img-blog.csdnimg.cn/70771ba13059499cadee1785c8a25a37.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/106c77654a8f4157a4c7ac5c9bb1ced6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_14,color_FFFFFF,t_70,g_se,x_16)

6、找到并打开Run中的Edit Configurations...选项,点击左上角加号选择Tomcat server中的Local

    在server选项中把路径改成本机中tomcat10文档,在Deployment选项中点击加号选择Artifact 

            ![](https://img-blog.csdnimg.cn/cfbc93f2330c446d8b7ff4eb3614d6d3.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/830f0f8b8261445e99a3431d5d16558e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/9bad50db2c79485195faa687805fd74b.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

7、在src ->new ->servlet,名给成Login。

            ![](https://img-blog.csdnimg.cn/c4c9f7c2d96047acaeee81511647c7de.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_12,color_FFFFFF,t_70,g_se,x_16)

8、打开Login文件,把文件中的两个@Override修改成下边的代码

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML>");
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>login</TITLE></HEAD>");
        out.println("  <BODY>");
        out.print("    this is login page");
        out.print(this.getClass());
        out.println("  </BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }
 
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML>");
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>login</TITLE></HEAD>");
        out.println("  <BODY>");
        out.print("    this is login page");
        out.print(this.getClass());
        out.println("  </BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }

9、找到web -> WEB-INF -> web.xml文档,在文档中添加下列代码。

  
<servlet>
        <servlet-name>JspWeb</servlet-name>
        <servlet-class>Login</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>JspWeb</servlet-name>
        <url-pattern>/Login</url-pattern>
    </servlet-mapping>
    ​​​​​​​        ![](https://img-blog.csdnimg.cn/62f80ffcd62244faaec3e921cfb8d777.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

10、最后运行,如果运行没有成功,没有跳转网页的话,把Login文档中@WebServlet那一行删除。

    ​​​​​​​        ![](https://img-blog.csdnimg.cn/df8cb6e2c3e64a7899a9099e9e7c7541.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_12,color_FFFFFF,t_70,g_se,x_16)

             ![](https://img-blog.csdnimg.cn/c3a25aec0e7d415e80a0e6fd60655541.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5Lic5b6I5LiN5oiz,size_20,color_FFFFFF,t_70,g_se,x_16)

11、再次运行,成功后在网址后面加上我们写的url(Login)就可以访问动态资源了。

标签: java tomcat jsp

本文转载自: https://blog.csdn.net/Dyoungwhite/article/details/122286892
版权归原作者 小东很不戳 所有, 如有侵权,请联系我们删除。

“idea中创建jsp项目详细步骤”的评论:

还没有评论