日期:2014-05-16  浏览次数:20378 次

新手提问,关于内嵌tomcat启动正常,访问jsp报404找不到resource
url : http://localhost:8898/studyPro/index.jsp

The requested resource (/studyPro/index.jsp) is not available.

load context log :
appPath:/studyPro
装载了Web应用studyPro
appPath:
装载了Web应用ROOT

init code:
          private void init() throws UnknownHostException {
		tomcat.setCatalinaHome(catalinaHome);

		Engine engine = tomcat.createEngine();
		engine.setName(engineName);

		Host host = tomcat.createHost("localhost", tomcat.getCatalinaHome()
				+ appBase);
		host.setAutoDeploy(true);

		if (logger.isInfoEnabled()) {
			logger.info("WebApp的根路径为" + appBase);
		}
		File baseDir = new File(tomcat.getCatalinaHome() + appBase);
		// 自动获取webapps下的war,就行解压和自动获取创建Context
		if (baseDir.exists()) {
			chkAndExtractWar(baseDir);
			File lstFile = new File(baseDir, "webapps.lst");
			// deploy文件jsp
			if (lstFile.exists()) {
				lstDeploy(host, baseDir);
			} else {
				defaultDeploy(host, baseDir);
			}
		}

		engine.setDefaultHost(host.getName());
		engine.addChild(host);

		tomcat.addEngine(engine);
		tomcat.setDebug(logLever);

		InetAddress ias = InetAddress.getByName("0.0.0.0");
		Connector connector = tomcat.createConnector(ias, port, false);
		if (connector instanceof CoyoteConnector) {
			CoyoteConnector cconnector = (CoyoteConnector) connector;
			cconnector.setURIEncoding("GBK");
		}
		tomcat.addConnector(connector);

		if (logger.isInfoEnabled()) {
			logger.info("创建连接器" + ias.getHostAddress() + ":" + port);
		}
	}


deploy代码:
    FileFilter appDirFF=new FileFilter(){
      public boolean accept(File pathname) {
        if( pathname.isDirectory()){
          //目录下必须有WEB-INF和WEB-INF/web.xml
          File webInf=new File(pathname,"WEB-INF");
          return webInf.exists() && new File(webInf,"web.xml").exists();
        }
        return false;
      }
    };
    
    //获取所有的目录,转换成Context并加载
    File[] appDirs=baseDir.listFiles(appDirFF);
    for (int i = 0; i < appDirs.length; i++) {
      String appDirName=appDirs[i].getName();
      String appPath="/"+appDirName;
      if("ROOT".equalsIgnoreCase(appDirName)){
        appPath="";
      }
      
      Context ctxRoot = tomcat.createContext(appPath,appDirName);
      ctxRoot.setPrivileged(true);
      ctxRoot.setReloadable(true);
      ctxRoot.addParameter("debug", "0");
      host.addChild(ctxRoot);
      if(logger.isInfoEnabled()) {
        logger.info("装载了Web应用"+appDirName);
      }
    }


用的是tomcat5.0.28做的demo导入的jar:
ant.jar
ant-launcher.jar
catalina.jar
catalina-optional.jar
commons-digester.jar
commons-el.jar
commons-modeler.jar
jakarta-regexp-1.3.jar
jasper-compiler.jar
jasper-runtime.jar
jsp-api.jar
mx4j-jmx.jar
naming-common.jar
naming-factory.jar
naming-java.jar
naming-resources.jar
servlet-api.jar
servlets-common.jar
servlets-default.jar
servlets-invoker.jar
tomcat-coyote.jar
tomcat-http11.jar
tomcat-jk2.jar
tomcat-util.jar
tools.jar


tools.jar已经换成工程jdk的版本下的tools.jar了

还是报不能访问资源,我是刚做内嵌tomcat的demo,是新手,请各位帮忙看看
1 楼 Dennis-lv 2008-07-06  
javaeye好大的名头,这么久没一个人有点建设意见~~
呵呵~~继续等,可能高手都在晚上出现吧
2 楼 brofe 2008-07-30  
高手出现了。