老师,出现一个问题

老师,出现一个问题

运行后,页面显示空白,在控制台有已下错误

D:\java\apache-tomcat-8.5.43\bin\catalina.bat run
[2019-11-23 01:35:01,515] Artifact icake:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE:   "C:\Users\Administrator.USER-20190331YS\.IntelliJIdea2019.2\system\tomcat\Unnamed_icake"
Using CATALINA_HOME:   "D:\java\apache-tomcat-8.5.43"
Using CATALINA_TMPDIR: "D:\java\apache-tomcat-8.5.43\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_101"
Using CLASSPATH:       "D:\java\apache-tomcat-8.5.43\bin\bootstrap.jar;D:\java\apache-tomcat-8.5.43\bin\tomcat-juli.jar"
Connected to the target VM, address: '127.0.0.1:50930', transport: 'socket'
23-Nov-2019 01:35:02.578 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.43
23-Nov-2019 01:35:02.583 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jul 4 2019 20:53:15 UTC
23-Nov-2019 01:35:02.583 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.43.0
23-Nov-2019 01:35:02.583 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 7
23-Nov-2019 01:35:02.584 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            6.1
23-Nov-2019 01:35:02.584 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
23-Nov-2019 01:35:02.584 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_101\jre
23-Nov-2019 01:35:02.584 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_101-b13
23-Nov-2019 01:35:02.584 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
23-Nov-2019 01:35:02.584 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\Administrator.USER-20190331YS\.IntelliJIdea2019.2\system\tomcat\Unnamed_icake
23-Nov-2019 01:35:02.584 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         D:\java\apache-tomcat-8.5.43
23-Nov-2019 01:35:02.587 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Administrator.USER-20190331YS\.IntelliJIdea2019.2\system\tomcat\Unnamed_icake\conf\logging.properties
23-Nov-2019 01:35:02.588 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
23-Nov-2019 01:35:02.588 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50930,suspend=y,server=n
23-Nov-2019 01:35:02.588 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -javaagent:C:\Users\Administrator.USER-20190331YS\.IntelliJIdea2019.2\system\captureAgent\debugger-agent.jar
23-Nov-2019 01:35:02.588 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
23-Nov-2019 01:35:02.589 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
23-Nov-2019 01:35:02.589 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
23-Nov-2019 01:35:02.589 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\Administrator.USER-20190331YS\.IntelliJIdea2019.2\system\tomcat\Unnamed_icake\jmxremote.password
23-Nov-2019 01:35:02.589 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\Administrator.USER-20190331YS\.IntelliJIdea2019.2\system\tomcat\Unnamed_icake\jmxremote.access
23-Nov-2019 01:35:02.589 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
23-Nov-2019 01:35:02.589 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
23-Nov-2019 01:35:02.589 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
23-Nov-2019 01:35:02.590 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
23-Nov-2019 01:35:02.590 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Administrator.USER-20190331YS\.IntelliJIdea2019.2\system\tomcat\Unnamed_icake
23-Nov-2019 01:35:02.590 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=D:\java\apache-tomcat-8.5.43
23-Nov-2019 01:35:02.590 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=D:\java\apache-tomcat-8.5.43\temp
23-Nov-2019 01:35:02.590 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.7.0].
23-Nov-2019 01:35:02.590 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
23-Nov-2019 01:35:02.591 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
23-Nov-2019 01:35:02.600 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1c  28 May 2019]
23-Nov-2019 01:35:02.776 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
23-Nov-2019 01:35:02.798 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
23-Nov-2019 01:35:02.820 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
23-Nov-2019 01:35:02.824 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
23-Nov-2019 01:35:02.825 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 716 ms
23-Nov-2019 01:35:02.876 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
23-Nov-2019 01:35:02.877 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.43
23-Nov-2019 01:35:02.890 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
23-Nov-2019 01:35:02.907 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
23-Nov-2019 01:35:02.911 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 86 ms
Connected to server
[2019-11-23 01:35:03,208] Artifact icake:war exploded: Artifact is being deployed, please wait...
23-Nov-2019 01:35:04.645 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 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.
[2019-11-23 01:35:04,782] Artifact icake:war exploded: Artifact is deployed successfully
[2019-11-23 01:35:04,782] Artifact icake:war exploded: Deploy took 1,574 milliseconds
java.lang.ClassNotFoundException: com.imooc.icake.Controller.CatalogController
com.imooc.icake.Controller.CatalogController
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1360)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1182)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.imooc.icake.global.GlobalController.service(GlobalController.java:55)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.imooc.icake.global.EncodingFilter.doFilter(EncodingFilter.java:18)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
com.imooc.icake.Controller.CatalogController
java.lang.ClassNotFoundException: com.imooc.icake.Controller.CatalogController
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1360)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1182)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.imooc.icake.global.GlobalController.service(GlobalController.java:55)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.imooc.icake.global.EncodingFilter.doFilter(EncodingFilter.java:18)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
23-Nov-2019 01:35:12.892 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\java\apache-tomcat-8.5.43\webapps\manager]
23-Nov-2019 01:35:13.071 信息 [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars 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.
23-Nov-2019 01:35:13.089 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\java\apache-tomcat-8.5.43\webapps\manager] has finished in [196] ms

我的GlobalController

package com.imooc.icake.global;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public  class GlobalController extends GenericServlet {
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        /*
        .do
        /login.do               DefaultController   login
        /Cake/detail.do         CakeController      detail
        /admin/Cake/add.do      CakeController      add
         */
        //强制类型转换
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        HttpServletResponse response=(HttpServletResponse) servletResponse;
        //获取用户请求的路径
        String path=request.getServletPath();
        if(path.indexOf("/admin")!=-1){
            //如果是后台“admin”的请求
            //从“/”后边开始截取
            path=path.substring(7);
        }else {
            //如果不是“admin”
            //从“/”后边开始截取
            path=path.substring(1);
        }
         /*
        .do
        login.do               DefaultController   login
        Cake/detail.do         CakeController      detail
        admin/Cake/add.do      CakeController      add
         */
         //通过请求路径 获得类名className。获得方法名methodName。
        String className=null;
        String methodName=null;
         int index=path.indexOf("/");
         if (index!=-1){
              className="com.imooc.icake.Controller."+path.substring(0,index)+"Controller";
            methodName=path.substring(index+1,path.indexOf(".do"));
         }else {
             className="com.imooc.icake.Controller.DefaultController";
             methodName=path.substring(0,path.indexOf(".do"));
         }
        try {
            //通过反射,执行这个方法
            System.out.println(className);
            Class cla=Class.forName(className);
            Object object=cla.newInstance();
            Method method=cla.getMethod(methodName,HttpServletRequest.class,HttpServletResponse.class);
            method.invoke(object,request,response);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

请问老师这个怎么解决

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

4回答
慕布斯37364 2019-11-23 15:35:55

1、可以在WEB-INF 前边加上斜杠/

http://img1.sycdn.imooc.com//climg/5dd8dfba090c99e906480451.jpg

2、路径是:/admin/Catalog/WEB-INF/pages/admin/catalog_list.jsp  是因为,没写/  是相对路径,转发时,是相对当前服务器的访问路径进程转发的,你应该是去访问的/ admin/Catalog/list. do 把,在当前路径下,由list方法进行转发就是在/ admin/Catalog这个路径的基础上转发到WEB-INF下,所以就出现了/admin/Catalog/WEB-INF/pages/admin/catalog_list.jsp 。

需要在WEB-INF前边加上/ ,也就是从根目录下去找WEB-INF。


提问者 Mr__Gao 2019-11-23 12:26:03
页面出现404这个错误

Type Status Report
Message /admin/Catalog/WEB-INF/pages/admin/catalog_list.jsp
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

我的CatalogController

package com.imooc.icake.controller;

import com.imooc.icake.biz.CatalogBiz;
import com.imooc.icake.biz.impl.CatalogBizImpl;
import com.imooc.icake.entity.Catalog;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CatalogController {

    private CatalogBiz catalogBiz=new CatalogBizImpl();

    //     /admin/Catalog/list.do
    public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Catalog root=catalogBiz.getRoot();
        request.setAttribute("root",root);
        request.getRequestDispatcher("WEB-INF/pages/admin/catalog_list.jsp").forward(request,response);
    }
    //     /admin/Catalog/toAdd.do
    public void toAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Catalog root=catalogBiz.getRoot();
        request.setAttribute("root",root);
        request.getRequestDispatcher("WEB-INF/pages/admin/catalog_add.jsp").forward(request,response);
    }
    //     /admin/Catalog/add.do
    public void add(HttpServletRequest request, HttpServletResponse response) throws IOException {

        String[] titles=request.getParameterValues("title");
        String[] pids=request.getParameterValues("pid");
        String[] infos=request.getParameterValues("info");
        List<Catalog> list=new ArrayList<Catalog>();
        for (int i=0;i<titles.length;i++){

            Catalog catalog=new Catalog();
            catalog.setTitle(titles[i]);
            catalog.setPid(Integer.parseInt(pids[i]));
            catalog.setInfo(infos[i]);
            list.add(catalog);
        }
        catalogBiz.add(list);
        response.sendRedirect("list.do");
    }
    //     /admin/Catalog/remove.do
    public void remove(HttpServletRequest request, HttpServletResponse response) throws IOException {

        int id=Integer.parseInt(request.getParameter("id"));
        catalogBiz.remove(id);
        response.sendRedirect("list.do");
    }
}

为什么会加载到这个页面/admin/Catalog/WEB-INF/pages/admin/catalog_list.jsp

而不是/admin/WEB-INF/pages/admin/catalog_list.jsp这里

芝芝兰兰 2019-11-23 12:02:27

同学你好。报错信息显示没有找到CatelogController这个类:

http://img1.sycdn.imooc.com//climg/5dd8ad6e0900da2307180079.jpg

同学可以检查下自己是否有com.imooc.icake.Controller这个包。这个包下是否有CatelogController这个类呢?注意大小写也要一致的

如果有,那么可能是缓存问题了。可以清除缓存再试:

1)清除idea缓存:

http://img1.sycdn.imooc.com//climg/5dd8ae82097d930003120445.jpg

2)清除浏览器缓存,windows系统使用快捷键“Ctrl+Shift+Delete”即可。

如果不是windows系统,Chrome浏览器地址栏中访问chrome://settings/clearBrowserData 点击确定即可。

3)重新编译项目:

http://img1.sycdn.imooc.com//climg/5dd8af15091c0b5404030221.jpg

然后重启Tomcat试一下~

祝学习愉快~


  • 提问者 Mr__Gao #1
    找到了啊啊
    2019-11-23 12:30:44
好帮手慕阿莹 2019-11-23 12:00:09

1、同学你好,请问同学的代码中是否存在这个CatalogController呢?

如果存在,它所在的包是:com.imooc.icake.Controller吗?

请同学贴下一这个Controller。以及同学的项目目录结构,

2、另外,老师猜测一下,同学包名中的Controller是本来就写的大写呢?还是不小心写错成大写的了呢?

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!


  • 提问者 Mr__Gao #1
    老师,我找到了 是不小心大写了,但是又出现一个新的问题 ,贴上边了
    2019-11-23 12:23:59
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师