D 的个人博客

但行好事莫问前程

  menu
417 文章
3446695 浏览
7 当前访客
ღゝ◡╹)ノ❤️

Tomcat6.0.13里Servlet映射问题与解决[00原创]

在做 Tomcat 6.0.13 配置时,修改如下。
将 Tomcat 的 web.xml 文件打开,去掉这 2 段代码上的注释:
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

再重新启动 Tomcat,就提示这个错误:启动时出现了问题:

2007-7-25 14:14:56 org.apache.catalina.core.AprLifecycleListener init
信 息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /home/daniel/Work/JDK/jre/lib/i386/client:/home/daniel/Work/JDK/jre/lib/i386:/home/daniel/Work/JDK/jre/../lib/i386:/home/daniel/Work/JDK/jre/lib/i386/client::/home/daniel/Work/JDK/jre/lib/i386::/usr/lib/mozilla-firefox:/usr/lib/mozilla-firefox:/usr/java/packages/lib/i386:/lib:/usr/lib
2007-7-25 14:14:56 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/
1.1 on http-8080
2007-7-25 14:14:56 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 
719 ms
2007-7-25 14:14:56 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2007-7-25 14:14:56 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/
6.0.13
2007-7-25 14:14:57 org.apache.catalina.startup.HostConfig deployDirectory
严重: Error deploying Web application directory ROOT
java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.InvokerServlet is privileged and cannot be loaded by this Web application
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:
1134)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:
981)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:
4042)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:
4348)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:
791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:
525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:
920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:
883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:
492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:
1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:
311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:
117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:
719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:
443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:
516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:
710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:
566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
    at java.lang.reflect.Method.invoke(Method.java:
597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:
288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:
413)
2007-7-25 14:14:57 org.apache.catalina.startup.HostConfig deployDirectory
严重: Error deploying Web application directory docs
java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.InvokerServlet is privileged and cannot be loaded by this Web application
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:
1134)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:
981)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:
4042)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:
4348)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:
791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:
525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:
920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:
883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:
492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:
1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:
311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:
117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:
719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:
443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:
516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:
710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:
566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
    at java.lang.reflect.Method.invoke(Method.java:
597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:
288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:
413)
2007-7-25 14:14:57 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2007-7-25 14:14:57 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2007-7-25 14:14:57 org.apache.catalina.startup.HostConfig deployDirectory
严重: Error deploying Web application directory examples
java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.InvokerServlet is privileged and cannot be loaded by this Web application
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:
1134)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:
981)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:
4042)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:
4348)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:
791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:
525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:
920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:
883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:
492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:
1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:
311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:
117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:
719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:
443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:
516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:
710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:
566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
    at java.lang.reflect.Method.invoke(Method.java:
597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:
288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:
413)
2007-7-25 14:14:57 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/
1.1 on http-8080
2007-7-25 14:14:57 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /
0.0.0.0:8009
2007-7-25 14:14:57 org.apache.jk.server.JkMain start
信息: Jk running ID
=0 time=0/40  config=null
2007-7-25 14:14:57 org.apache.catalina.startup.Catalina start
信息: Server startup in 
968 ms



解决方法:
在 conf/context.xml 中的<Context>标签中添加参数 privileged="true",即修改为<Context privileged="true">。