本篇文章
 
环境:win7 + jdk1.7 + tomcat v8.0.53
 
工具:
1.Eclipse 
Eclipse Java EE IDE for Web Developers.
Version: Luna Service Release 2 (4.4.2)
Build id: 20150219-0600
 
 
2. tomcat v8.0.53
 
知识点:java + servlet + tomcat
 
创建web工程方法
1. File --- new  --- Dynamic Web Project 
 
 

 

看图说话:
a. 填写web工程名:First
b. 点击“New Runtime...“,”选择“Apache Tomcat v8.0”(PS:由于Eclipse luna最大支持 Apache Tomcat v8.0,所以PC端最大只能安装tomcat v8版本,不支持v9)
c. 点击"Next"
 
然后如下:
 

 
a. 选择tomcat 在本地的位置
b. 选择"JRE"
c. 点击finish
 
然后如下:
 

 
点击“Next”
 
 

 
点击“Next”
 
 

 
勾选“Generate web.xml ...”,这样,可以自动生成web.xml文件,点击“finish”按钮
 
项目创建完成:
 
 

 
2. 创建servlet
 
 

 
 
点击“Next”
 
 
 

点击“Next”
 

 
 
直接点击“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();
       }
}
 
3. 修改web.xml 文件为:
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
       <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>
 
备注:上面高亮部分的名称要一致
 
 
 

 
4. 开始部署
 
 
 

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

5. 运行servlet
 
选中“ServletDemo1”--- 右键 --- Run As --- Run on Server
 
 

 

点击“finish”按钮,运行效果如下,成功!
 
 

 
 
 
PS:
 
 
2.打印log方法:
 
方法一:
将 commons-logging-1.1.1.jar 拷贝到 libs文件夹:
 
 
private static Log log1 = LogFactory.getLog(ServletDemo1.class);
 
doGet方法内加入:log1.info("!!!!");
 
方法二:
System.out.println("xxx");
 
方法三:
getServletContext().log("xxx");
 
注意:加入log日志后,如果log不生效,clean下工程:

然后在浏览器输入:http://localhost:8080/First/test/ServletDemo1,回车后,可以看到日志输出

 
 

Android 本地tomcat服务器接收处理手机上传的数据之环境搭建的更多相关文章

  1. Android 本地tomcat服务器接收处理手机上传的数据之案例演示

    上一篇:Android 本地tomcat服务器接收处理手机上传的数据之环境搭建     本篇基于上一篇搭建的服务器端环境,具体介绍Android真机上传数据到tomcat服务器的交互过程   场景:A ...

  2. 利用exif.js解决ios或Android手机上传竖拍照片旋转90度问题

    html5+canvas进行移动端手机照片上传时,发现ios手机上传竖拍照片会逆时针旋转90度,横拍照片无此问题:Android手机没这个问题. 因此解决这个问题的思路是:获取到照片拍摄的方向角,对非 ...

  3. (2)MyEclipse怎么关联本地Tomcat服务器

    1,在MyEclipse中点击服务器按钮: 2,选择“Configure Server” 3,在弹出面板中选择 [Servers]-[Tomcat]-[对应版本的服务器] 5,看上图,先选择Enabl ...

  4. 利用exif.js解决ios手机上传竖拍照片旋转90度问题

    html5+canvas进行移动端手机照片上传时,发现ios手机上传竖拍照片会逆时针旋转90度,横拍照片无此问题:Android手机没这个问题. 因此解决这个问题的思路是:获取到照片拍摄的方向角,对非 ...

  5. 转 Android网络编程之使用HttpClient批量上传文件 MultipartEntityBuilder

    请尊重他人的劳动成果,转载请注明出处:Android网络编程之使用HttpClient批量上传文件 http://www.tuicool.com/articles/Y7reYb 我曾在<Andr ...

  6. 解决ios手机上传竖拍照片旋转90度问题

    html5+canvas进行移动端手机照片上传时,发现ios手机上传竖拍照片会逆时针旋转90度,横拍照片无此问题:Android手机没这个问题. 因此解决这个问题的思路是:获取到照片拍摄的方向角,对非 ...

  7. 利用exif.js解决手机上传竖拍照片旋转90\180\270度问题

    原文:https://blog.csdn.net/linlzk/article/details/48652635/ html5+canvas进行移动端手机照片上传时,发现ios手机上传竖拍照片会逆时针 ...

  8. android中的文件(图片)上传

    android中的文件(图片)上传其实没什么复杂的,主要是对 multipart/form-data 协议要有所了解. 关于 multipart/form-data 协议,在 RFC文档中有详细的描述 ...

  9. 学习Git的一点心得以及如何把本地修改、删除的代码上传到github中

    一:学习Github的资料如下:https://git.oschina.net/progit/ 这是一个学习Git的中文网站,如果诸位能够静下心来阅读,不要求阅读太多,只需要阅读前三章,就可以掌握Gi ...

随机推荐

  1. S 参数说明

     微波系统主要研究信号和能量两大问题:信号问题主要是研究幅频和相频特性:能量问题主要是研究能量如何有效地传输.微波系统是分布参数电路,必须采用场分析法,但场分析法过于复杂,因此需要一种简化的分析方法. ...

  2. 在Android平台下搭建PhoneGap开发环境--用HTML5开发游戏

    一.在Android平台下搭建PhoneGap开发环境具体怎么搭建我这里就不详细说了,如有需要我后面再讲 . PhoneGap 官方地址有详细说明:http://www.phonegap.com. 在 ...

  3. VVDocumenter规范注释生成器

    下载地址:https://github.com/onevcat/VVDocumenter-Xcode PS:Xcode 8.0 默认支持了,但是是关闭状态,需要在终端输入如下命令开启,然后重启 Xco ...

  4. [Unity3D]关于NaN(Not a Number)的问题

    在游戏运行时,代码若写得不安全很容易出现NAN的异常.一旦NAN出现整个游戏不崩溃也坏死掉了,游戏上了则是要被直接打回来的节奏,更是一个开发及测试人员每人都要扣3000块的大BUG.   一般表现为: ...

  5. CentOS 7中添加一个新用户并授权

    Linux 创建web用户组及用户: groupadd www-data useradd -g www-data www-data 笔记本安装了一个CentOS,想要让别人也可以登录访问,用自己的账号 ...

  6. Linux Device Tree

     原创博文,转载请标明出处--周学伟 http://www.cnblogs.com/zxouxuewei/ 设备树使用手册 基本数据格式 设备树是一个包含节点和属性的简单树状结构.属性就是键-值对,而 ...

  7. systemctl命令完全指南

    Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器. Systemd是一个系统管理守护进程.工具和库的集合,用于取代System V初始进程.Systemd的功能是 ...

  8. 在CentOS Linux下部署Activemq 5

    准备:安装之前首先安装jdk-1.7.x及以上版本 配置/etc/sysconfig/network文件 和/etc/hosts文件,把主机名的解析做清楚: 如: # cat /etc/sysconf ...

  9. python --help查询python相关命令

    C:\Users\lenovo>python --help usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... O ...

  10. asp.net 验证码

    Before proceeding with the topic first we must understand "What is a Captcha code?" and &q ...