- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
package sampleJSN;
import java.io.IOException;
import java.util.Set;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Init implements ServletContainerInitializer {
@SuppressWarnings("serial")
@Override
public void onStartup(Set<Class<?>> arg0, ServletContext arg1) throws ServletException {
System.out.println("ssd");
HttpServlet serv = new HttpServlet() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.getWriter().write("<b>JSN</b>");
}
@Override
public void init(ServletConfig config) throws ServletException {
System.out.println("sirappu");
super.init(config);
}
};
Dynamic dyc = arg1.addServlet("Name", serv);
dyc.addMapping("/jsn");
}
}
我正在编写一个程序来测试 ServletContainerInitializer。问题是 ServletContainerInitializer 本身工作正常,并且打印了 ServletContainerInitializer.onStartup is called "ssd",但是 ServletContext.addServlet 没有注册我的 servlet,因此没有调用 init 方法。请检查下面的日志
Apr 11, 2018 12:18:45 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:CheckWeb' did not find a matching property.
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.36
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jun 9 2016 13:55:50 UTC
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.36.0
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 8.1
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.3
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_161\jre
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_161-b12
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\BalajiGold\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\tomcat-8
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:63748
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\BalajiGold\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\tomcat-8
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\BalajiGold\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\tomcat-8\endorsed
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Apr 11, 2018 12:18:45 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_161\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jdk1.8.0_161\jre\bin;C:/Program Files/Java/jdk1.8.0_121/jre/bin/server;C:/Program Files/Java/jdk1.8.0_121/jre/bin;C:/Program Files/Java/jdk1.8.0_121/jre/lib/amd64;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\system32;C:\Windows;C:\Program Files\QuickTime\QTSystem;C:\cygwin64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\MinGW\bin;C:\MinGW\MSYS\1.0\bin;C:\Program Files\Git\bin;C:\Users\BalajiGold\AppData\Local\Programs\Eclipse Che\eclipse-che-5.0.0\tools\jre\bin;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\Java\jdk1.8.0_161\bin;C:\Program Files\Docker Toolbox;C:\apache-maven-3.5.2\bin;C:\Users\BalajiGold\Desktop;;.
Apr 11, 2018 12:18:45 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Apr 11, 2018 12:18:45 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 11, 2018 12:18:45 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Apr 11, 2018 12:18:45 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 941 ms
Apr 11, 2018 12:18:45 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 11, 2018 12:18:45 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.36
Apr 11, 2018 12:18:48 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 11, 2018 12:18:50 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
ssd
Apr 11, 2018 12:18:54 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Apr 11, 2018 12:18:54 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Apr 11, 2018 12:18:54 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9179 ms
最佳答案
dyc.setLoadOnStartup(0);
这段代码为我解决了上述问题
PS:别忘了添加META-INF/services/javax.servlet.ServletContainerInitializer
关于java - ServletContainerInitializer 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49760995/
package sampleJSN; import java.io.IOException; import java.util.Set; import javax.servlet.ServletCon
我正在尝试使用 servletContainerInitializer 注册一个 servlet,但它似乎不起作用,也许这是我的代码(请查看它),但我开始想知道 ServletContainerIni
是否可以阻止提供的 jar 的 ServletContainerInitializer 的执行。 我想阻止 JerseyServletContainerInitializer.java 的执行它由 G
我必须创建一个实现 ServletContextListener 的类在 Tomcat 初始化或关闭期间添加事件。但是,该类必须位于 WEB-INF/lib 内的 jar 文件中。在做了一些阅读之后,
我想将我的 springboot 应用程序(war)部署到 apache tomcat 8,我已经在我的类中扩展了 SpringBootServletInitializer,并在我的 pom.xml
我在 I 类中有我的 servlet 配置,它扩展了 ServletContainerInitializer。我在那里注册 servlet 并定义映射。我不想在我的集成测试中做同样的工作。有没有常见的
我正在尝试将基于 xml 的 Spring MVC 应用程序移动到基于 Java 配置的应用程序。似乎与 maven 中可用的各种 java.servlet 类不匹配。例如,有些提供 addServl
我这样创建 Grizzly WebappContext: WebappContext webContext = new WebappContext("WebappContext", ""); 我有 M
我正在创建一个包含以下依赖项的 OSGi 包 tomcat-dbcp tomcat-embed-core tomcat-embed-jasper tomcat-embed-websocket tomc
在我将 javaee-web-api-7.0.jar 添加到我的 JSF 项目后,它停止工作并出现错误: org.apache.catalina.startup.ContextConfig.proce
我正在编写一些 servlet,它们都运行良好 Tomcat 运行时没有任何问题。然后我编写了一个使用 JERSEY 的类文件,当我尝试运行它时,Tomcat 无法启动。我在 Eclipse 中安装了
我想使用 ServletContainerInitializer 映射 REST API,我的代码是 @Override public void onStartup(Set> classes, Ser
能否在web.xml文件中指向一个实现ServletContainerInitializer接口(interface)的类,还是必须在META-INF/下添加一个文件services/javax.se
尝试通过 gradle 运行 tomcatRun 任务时出现此错误显然这是由于依赖性问题引起的。我的 build.gradle 文件粘贴在下面: apply plugin: 'war' app
我有一个 Web 项目,它有一个 \META-INF\services\javax.servlet.ServletContainerInitializer 文件,其内容指向实现 ServletCont
根据我的理解,3.0 servlet 容器应该扫描类路径以查找 ServletContainerInitializer 接口(interface)的实现(即 springs )。随后这应该调用 Web
我正在尝试用从 Spring 的 WebApplicationInitializer 扩展的基于代码的类替换我的 web.xml 文件。我的 web.xml 文件有几个“env-entry”元素。我试
请让我先告诉你我打算做什么。我打算完全按照 Springframework 网站中提到的“构建 RESTful Web 服务”教程进行操作 http://spring.io/guides/gs/res
我正在使用 Spring 4.3 和 Servlet 3.1。部署失败并出现错误 javax.servlet.ServletContainerInitializer:提供程序 org.springfr
我有七个在 Spring 3.2 中开发的 Web 应用程序,全部基于注释。我使用 Hibernate 4.2 作为我的 ORM 框架。 我创建了一个 tomcat 镜像,其中包含所有 7 个 war
我是一名优秀的程序员,十分优秀!