Android本地tomcat服务器接收处理手机上传的数据之环境搭建

创建一个Dynamic Web Project项目在这里插入图片描述
选择服务器
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
next,next
在这里插入图片描述
勾选,Finish
在这里插入图片描述
创建成功

创建servlet
在这里插入图片描述
Finish

修改 ServletDemo1.java文件,内容如下:

package com.servlet.demo;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class ServletDemo1
 */
@WebServlet(asyncSupported = true, urlPatterns = { "/ServletDemo1" })
public class ServletDemo1 extends HttpServlet {
       private static final long serialVersionUID = 1L;
       /**
        * 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();
       }
}

修改web.xml 文件为:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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_3_1.xsd">
       <welcome-file-list>
             <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
        <servlet>
             <servlet-name>ServletDemo1</servlet-name>//这句要注意名字一样
             <servlet-class>com.servlet.demo.ServletDemo1</servlet-class>
       </servlet>
       <servlet-mapping>
             <servlet-name>ServletDemo1</servlet-name>//这句要注意名字一样
             <url-pattern>/test/ServletDemo1</url-pattern>
       </servlet-mapping>
</web-app>

开始部署

在这里插入图片描述
在这里插入图片描述
直接点击“finish”按钮,如下(虽然出现Not Found,此时不要担心,还没开始运行servlet 呢,继续往下看):在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在网址中输入
在这里插入图片描述
可以看到,能通过服务器执行代码

本文转自:https://www.cnblogs.com/onelikeone/p/9958108.html

解决Tomcat v9.0 Server at localhost are already in use
在这里插入图片描述
直接进行services.msc
在这里插入图片描述
找到Apache 这种奇葩
在这里插入图片描述
在这里插入图片描述
重新运行eclipse的工程就好了
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值