学习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. linux入门系列3--常见的linux远程登陆管理工具

    服务器一般是云服务器或者放置在机房,我们日常工作中通过远程连接工具连接到服务器进行操作,这类工具很多(如SecureCRT.XShell.Putty.FinallShell.TeamViewer以及w ...

  2. Quartz 和 springboot schedule中的cron表达式关于星期(周几)的不同表示

    一.Quartz中cron 表达式分析: quartz 官方源码(org.quartz.CronExpression)解释: Cron expressions are comprised of 6 r ...

  3. Web及网络基础学习(一)

    ---恢复内容开始--- 2019.10.16 1.TCP.IP分层  应用层.网络层.传输层.数据链路层 2.各层讲解 应用层 决定了向用户提供应用服务时通信的活动.例如FTP(File Trans ...

  4. Qt5学习(1)

    1. In Qt, if you want to apply styles to the main window  itself, you must apply it to  its central ...

  5. ubuntu下报错Sub-process /usr/bin/dpkg returned an error code (1)的解决方法

    cd /var/lib/dpkg sudo mv info info.bak #即备份一个info sudo mkdir info #新建一个新的info目录 然后采用以下命令重装那些出错的软件包 s ...

  6. The command '/bin/sh -c unzip -o php-7.2.23-src.zip' returned a non-zero code: 1

    Dockerfile 内容 #centos7 nginx php redis inotify FROM centos:7 MAINTAINER INFOBIRD RUN yum -y update & ...

  7. goland编辑器永久激活

    1 下载goland破解文件补丁 链接: https://pan.baidu.com/s/1i3dFAwscXPzKV-1imvgkdA 提取码: furt 2 打开goland的安装文件,将下载好的 ...

  8. 最大流入门题目 - poj 1273

    Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This ...

  9. dubbo配置文件解读(1)

    详细的Dubbo配置也可以参考:https://blog.csdn.net/abcde474524573/article/details/53026110 (1)<dubbo:service/& ...

  10. <a>标签的href和onclick属性【转】

    1链接的onclick 事件被先执行,其次是href属性下的动作(页面跳转,或 javascript 伪链接): 2假设链接中同时存在href 与onclick,如果想让href 属性下的动作不执行, ...