小鱼Ava 2017-02-06 22:45 采纳率: 60%
浏览 2795
已采纳

学习Servlet时运行报错,如何解决?

JSP页面错误
type Exception report

message Error instantiating servlet class com.rl.servlet.ServeltDemo1

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class com.rl.servlet.ServeltDemo1
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)

root cause

java.lang.IllegalAccessException: Class org.apache.catalina.core.DefaultInstanceManager can not access a member of class com.rl.servlet.ServeltDemo1 with modifiers ""
sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)

note The full stack trace of the root cause is available in the Apache Tomcat/8.0.32 logs.

控制台报错
严重: Allocate exception for servlet helloServlet
java.lang.IllegalAccessException: Class org.apache.catalina.core.DefaultInstanceManager can not access a member of class com.rl.servlet.ServeltDemo1 with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:119)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1102)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:828)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

**实现类代码**:
class ServeltDemo1 implements Servlet {
@Override
public void init(ServletConfig arg0) throws ServletException {
    System.out.println("相应请求");
    System.out.println("Servlet组件被创建了");

}
@Override
public void service(ServletRequest request, ServletResponse response)
        throws ServletException, IOException {
    response.getOutputStream().write("<font color = 'red'>Hello Servlet</font>".getBytes());
}
@Override
public void destroy() {
    System.out.println("Servlet销毁了");
}

}

web.xml代码
<?xml version="1.0" encoding="UTF-8"?>


<!-- 设置Servlet名称 -->
helloServlet
<!-- 具体的Servlet类 -->
com.rl.servlet.ServeltDemo1


helloServlet
/hello

展开全部

  • 写回答

3条回答 默认 最新

  • 小鱼Ava 2017-06-21 19:28
    关注

    实现类添加public
    实现类代码
    public class ServeltDemo1 implements Servlet {
    @Override
    public void init(ServletConfig arg0) throws ServletException {
    System.out.println("相应请求");
    System.out.println("Servlet组件被创建了");

    }
    @Override
    public void service(ServletRequest request, ServletResponse response)
    throws ServletException, IOException {
    response.getOutputStream().write("Hello Servlet".getBytes());
    }
    @Override
    public void destroy() {
    System.out.println("Servlet销毁了");
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 uni-app动态修改推荐页标题时报错
  • ¥15 图片是GET请求,后面是图片的id,Glide如何缓存?
  • ¥15 现代密码学问题求解答
  • ¥15 关于C#与NICAN类库通信的问题
  • ¥15 cytoscape问题
  • ¥15 putty实现机器学习猫狗识别
  • ¥15 STS/eclipse导入gradle项目时报错如下
  • ¥15 centos7.6进不去系统,卡在数字7界面
  • ¥15 Tensorflow采用interpreter.allocate_tensors()分配内存出现ValueError: vector too long报错
  • ¥15 使用CGenFF在线生成血红素辅基拓扑结构遇到问题
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部