学习Servlet时碰到的一个bug。

Connected to server

[2017-01-08 04:40:33,100] Artifact jspRun:war exploded: Artifact is being deployed, please wait...

08-Jan-2017 16:40:33.570 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 

org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Servlet]]

at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:441)

说说解决的思路:

因为不记得对项目做了哪些更改,所以

重新配置一次Servlet环境,没有出现任何问题。

说明我们Tomcat与Intellij是没有问题的。

那么问题只能出现在:

1、代码问题。

2、当前项目属性设置问题。

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration; /**
* Created by N3verL4nd on 2017/1/4.
*/
@WebServlet(name = "testServlet", urlPatterns = {"test.do"})
public class testServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>TEST</title>");
out.println("</head>");
out.println("<body>"); out.println(request.getRequestURI() + "<br />");
out.println(request.getContextPath() + "<br />");
out.println(request.getServletPath() + "<br />"); Enumeration<String> names = request.getHeaderNames();
while (names.hasMoreElements()){
String name = names.nextElement();
out.println(name + ":" + request.getHeader(name) + "<br />");
}
out.println("</body>");
out.println("</html>");
out.close();
}
}

以上是测试代码,经检查是

@WebServlet(name = "testServlet", urlPatterns = {"test.do"})

使用出错。

@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
public @interface WebServlet
This annotation is used to declare the configuration of an Servlet

If the name attribute is not defined, the fully qualified name of the class is used.



At least one URL pattern MUST be declared in either the value or urlPattern attribute of the annotation, but not both.



The value attribute is recommended for use when the URL pattern is the only attribute being set, otherwise the urlPattern attribute should be used.



The class on which this annotation is declared MUST extend HttpServlet



E.g. @WebServlet("/path")}

public class TestServlet extends HttpServlet ... {


E.g. @WebServlet(name="TestServlet", urlPatterns={"/path", "/alt"}) 

public class TestServlet extends HttpServlet ... {

Since:
Servlet 3.0 (Section 8.1.1)

使用@WebServlet将一个继承于javax.servlet.http.HttpServlet的类定义为Servlet组件。

@WebServlet有很多的属性:

asyncSupported:声明Servlet是否支持异步操作模式。

description:    Servlet的描述。

displayName:     Servlet的显示名称。

initParams:        Servlet的init参数。

name:        Servlet的名称。

urlPatterns:    Servlet的访问URL。

value:          Servlet的访问URL。

Servlet的访问URL是Servlet的必选属性,可以选择使用urlPatterns或者value定义。

urlPatterns或者value的写法有以下几种:

1.完全匹配  要求以/开始,名称与url一致.

2.使用通配符  *

3.目录匹配   以/开始,以*结束.

4.扩展名匹配.    不能以/开始,以*.xxx对束



参考:

http://www.cnblogs.com/fangjian0423/p/servletContainer-tomcat-urlPattern.html

详细解释:

@WebServlet

@WebServlet 用于将一个类声明为 Servlet,该注解将会在部署时被容器处理,容器将根据具体的属性配置将相应的类部署为 Servlet。该注解具有下表给出的一些常用属性(以下所有属性均为可选属性,但是 vlaue 或者 urlPatterns 通常是必需的,且二者不能共存,如果同时指定,通常是忽略 value 的取值):

表 1. @WebServlet 主要属性列表

属性名 类型 描述
name String 指定 Servlet 的 name 属性,等价于 <servlet-name>。如果没有显式指定,则该 Servlet 的取值即为类的全限定名。
value String[] 该属性等价于 urlPatterns 属性。两个属性不能同时使用。
urlPatterns String[] 指定一组 Servlet 的 URL 匹配模式。等价于 <url-pattern> 标签。
loadOnStartup int 指定 Servlet 的加载顺序,等价于 <load-on-startup> 标签。
initParams WebInitParam[] 指定一组 Servlet 初始化参数,等价于 <init-param> 标签。
asyncSupported boolean 声明 Servlet 是否支持异步操作模式,等价于 <async-supported> 标签。
description String 该 Servlet 的描述信息,等价于 <description> 标签。
displayName String 该 Servlet 的显示名,通常配合工具使用,等价于 <display-name> 标签。

下面是一个简单的示例:

@WebServlet(urlPatterns = {"/simple"}, asyncSupported = true,
loadOnStartup = -1, name = "SimpleServlet", displayName = "ss",
initParams = {@WebInitParam(name = "username", value = "tom")}
)
public class SimpleServlet extends HttpServlet{ … }

如此配置之后,就可以不必在 web.xml 中配置相应的 <servlet> 和 <servlet-mapping> 元素了,容器会在部署时根据指定的属性将该类发布为 Servlet。它的等价的 web.xml 配置形式如下:

<servlet>
<display-name>ss</display-name>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>footmark.servlet.SimpleServlet</servlet-class>
<load-on-startup>-1</load-on-startup>
<async-supported>true</async-supported>
<init-param>
<param-name>username</param-name>
<param-value>tom</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/simple</url-pattern>
</servlet-mapping>

严重 [RMI TCP Connection(3)-127.0.0.1]的更多相关文章

  1. 严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:解决

    严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal Contain ...

  2. ERROR [RMI TCP Connection(3)-127.0.0.1] - init datasource error

    运行报错 ERROR [RMI TCP Connection(3)-127.0.0.1] - init datasource error, url: jdbc:mysql://localhost:33 ...

  3. Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space

    在Eclipse 调试 springside showcase项目中,tomcat报异常 Exception in thread "RMI TCP Connection(idle)" ...

  4. Debian部署RMI异常:java.rmi.ConnectException: Connection refused to host: 127.0.1.1;

    现象:在windows上部署RMI很顺利,但移到debian上部署后,客户端报异常: java.rmi.ConnectException: Connection refused to host: 12 ...

  5. 调用远程主机上的 RMI 服务时抛出 java.rmi.ConnectException: Connection refused to host: 127.0.0.1 异常原因及解决方案

    最近使用 jmx 遇到一个问题,client/server 同在一台机器上,jmx client能够成功连接 server,如果把 server 移植到另一台机器上192.168.134.128,抛出 ...

  6. Error: client: etcd cluster is unavailable or misconfigured; error #0: dial tcp 127.0.0.1:4001: getsockopt: connection refused

    配置docker网络flannel时,配置etcd的key的时候出现以下错误 Error:  client: etcd cluster is unavailable or misconfigured; ...

  7. Go丨语言对数据库操作报错 panic: dial tcp 127.0.0.1:3306: connectex: No connection could be made because the target machine actively refused it.

    panic: dial tcp 127.0.0.1:3306: connectex: No connection could be made because the target machine ac ...

  8. postgresql connection failure:SQLSTATE[08006] [7] could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

    PHP 程序无法连接到 CentOS 上的PostgreSQL,但是在 CentOS 服务器上却能正常运行 psql, 操作如下:多次重启 PG 数据库后发现 CGI 脚本无法连接数据库,但是可以使用 ...

  9. telnet: connect to address 127.0.0.1: Connection refused

    telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式.它为用户提供了在本地计算机上完成远程主机工作的能力.在终端使用者的电脑上使用telnet程序,用它连接 ...

随机推荐

  1. Tomcat启动失败原因

    Tomcat启动失败原因 一.Tomcat启动时,要求被加载的项目必须拥有独立路径名称 发布的两个工程具有相同路径名称,这是不允许. 二.8080端口号已经被占用了 启动失败原因,就是8085端口上, ...

  2. 微服务统计,分析,图表,监控一体化的HttpReports项目在.Net Core 中的使用

    简单介绍 HttpReports 是 .Net Core 下的一个Web项目, 适用于WebAPI,Ocelot网关应用,MVC项目,非常适合针对微服务应用使用,通过中间件的形式集成到您的项目中,可以 ...

  3. docker故障排查

    代理服务器设置 代理服务器可以在启动并运行后阻止与Web应用程序的连接.如果您位于代理服务器后面,请使用以下ENV命令将以下行添加到Dockerfile中,以指定代理服务器的主机和端口: # Set ...

  4. 13.利用pymysql创建变量类型的表名解说

    在练习爬虫爬取数据时,想将爬取的数据用pymysql存储到数据库中,并且存储时的表名是一个变量,但在写完代码运行后经常出面1064的错误代码,在网上查找相关解决方法,但一直找不到完美的解决方法, 通过 ...

  5. 端口扫描器--利用python的nmap模块

    安装nmap模块挺麻烦的,搞了半天 不仅要安装pip install nmap 还要sudo apt install nmap 给出代码,没有设多线程,有点慢,注意端口的类型转换,搞了很久 #!/us ...

  6. Akka Java 中文文档

    Akka Java 中文文档 Introduction What is Akka? | 什么是Akka? Why Akka? | 为什么选择Akka? Getting Started | Akka入门 ...

  7. 《利用python进行数据分析》——Numpy基础

    一.创建数组 1.创建数组的函数 array:将输入数据(列表.元组.数组或其他序列类型)转换为ndarray,可用dtype指定数据类型. >>> import numpy as ...

  8. LeetCode 第17题--电话号码的组合(DFS)

    1. 题目 2.题目分析与思路 3.代码 1. 题目 输入:"23" 输出:["ad", "ae", "af", &qu ...

  9. C# 添加、删除、读取Word形状(基于Spire.Cloud.Word.SDK)

    本文介绍调用Spire.Cloud.Word.SDK提供的接口shapesApi来操作Word形状,包括添加形状AddShape(),添加形状时,可设置形状类型.颜色.大小.位置.倾斜.轮廓.文本环绕 ...

  10. JsonResponse和HttpResponse

    1.联系 JsonResponse继承HttpResponse 2.区别 JsonResponse 数据类型装自动换成json字符串并相应到前端,传到前端的是数据类型而非json字符串 HttpRes ...