第一个Web项目

步骤:

1创建一个Web Project

2创建一个Servlet

3配置web.xml文件。

4)测试。

----------------------------------

1)创建JqueryPulgin工程。

2)创建Servlet

package org.ws.test;

 

import java.io.IOException;

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

public class ServletTest extends HttpServlet {

 

    /**

     * Constructor of the object.

     */

    public ServletTest() {

       super();

    }

 

    /**

     * Destruction of the servlet. <br>

     */

    public void destroy() {

       super.destroy(); // Just puts "destroy" string in log

       // Put your code here

    }

 

    /**

     * The doGet method of the servlet. <br>

     *

     * This method is called when a form has its tag value method equals to get.

     *

     * @param request the request send by the client to the server

     * @param response the response send by the server to the client

     * @throws ServletException if an error occurred

     * @throws IOException if an error occurred

     */

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

 

       response.setContentType("text/html");

       PrintWriter out = response.getWriter();

       out.println("<!DOCTYPE HTML PUBLIC /"-//W3C//DTD HTML 4.01 Transitional//EN/">");

       out.println("<HTML>");

       out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");

       out.println("  <BODY>");

       out.print("    This is ");

       out.print(this.getClass());

       out.println(", using the GET method");

       out.println("  </BODY>");

       out.println("</HTML>");

       out.flush();

       out.close();

    }

 

    /**

     * The doPost method of the servlet. <br>

     *

     * This method is called when a form has its tag value method equals to post.

     *

     * @param request the request send by the client to the server

     * @param response the response send by the server to the client

     * @throws ServletException if an error occurred

     * @throws IOException if an error occurred

     */

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

 

       response.setContentType("text/html");

       PrintWriter out = response.getWriter();

       out.println("<!DOCTYPE HTML PUBLIC /"-//W3C//DTD HTML 4.01 Transitional//EN/">");

       out.println("<HTML>");

       out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");

       out.println("  <BODY>");

       out.print("    This is ");

       out.print(this.getClass());

       out.println(", using the POST method");

       out.println("  </BODY>");

       out.println("</HTML>");

       out.flush();

       out.close();

    }

 

    /**

     * Initialization of the servlet. <br>

     *

     * @throws ServletException if an error occurs

     */

    public void init() throws ServletException {

       // Put your code here

    }

 

}

 

 

3web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4"

    xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <servlet>

    <description>This is the description of my J2EE component</description>

    <display-name>This is the display name of my J2EE component</display-name>

   

    <servlet-name>ServletTest</servlet-name>

    <servlet-class>org.ws.test.ServletTest</servlet-class>

  </servlet>

 

  <servlet-mapping>

    <servlet-name>ServletTest</servlet-name>

    <url-pattern>/*</url-pattern>

  </servlet-mapping>

 

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>

 

 

4)测试url

http://192.168.0.144:8080/JQueryPulgin/ServletTest

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在IDEA中创建一个web项目,可以按照以下步骤进行操作: 1. 新建一个Java模块,命名为webDemo1。 2. 右键选择webDemo1模块,然后选择"Add Framework Support"。 3. 在添加的框架中选择"Web Application"。 另外,还可以按照以下步骤进行操作: 1. 点击菜单栏中的"Add Framework Support"。 2. 选择"Web Application"。 3. 成功后,会在项目中出现一个带有蓝色点的web包。 接下来是项目的配置: 4. 在WEB-INF文件夹下新建一个名为"classes"的文件夹和一个名为"lib"的文件夹。 5. 打开项目结构(Project Structure)。 6. 进行项目配置。 7. 进行模块配置。 8. 进行Facets配置,这里指定了web目录不是一个普通的文件夹,而是一个web项目。 然后是配置Artifacts: 9. 配置Artifacts。 10. 添加Tomcat服务器。 11. 配置Deployment,这个操作可以让Tomcat找到war包所在的位置,从而将web项目部署在Tomcat服务器上。 最后是添加项目所需要的依赖: 12. 导入lib目录下的jar包,这些是web项目所需的jar包。 13. 导入与Tomcat相关的jar包。 完成以上配置后,可以运行服务,成功运行web项目。 除此之外,您还可以编写第一个servlet来进行测试。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [idea构建web项目-超详细教程](https://blog.csdn.net/stepleavesprint/article/details/127776102)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [IDEA中创建WEB项目](https://blog.csdn.net/weixin_46503238/article/details/120887417)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值