本文介绍了无法在Jetty Web应用程序中加载Java脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的web应用程序,我尝试使用 flot javascript库绘制图形.我的JSP文件是按以下方式导入所需的* .js文件的.

I have a very simple webapp where I am trying to plot graphs using flot javascript library. My JSP file goes this way where I am importing the required *.js files as follows.

相对于WEB-INF/pages/hello.jsp中的hello.jsp文件,具有相关.js文件的脚本目录位于../../scripts(即直接位于ROOT下)

Relative to the hello.jsp file at WEB-INF/pages/hello.jsp, scripts directory with the relevant .js files are at ../../scripts (i.e. directly under ROOT)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Flot Examples: Categories</title>
    <script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>
    <script language="javascript" type="text/javascript" src="../../scripts/jquery.flot.js"></script>
    <script type="text/javascript">

    $(function() {
     //code draw the graph
    </script>
</head>
<body>
        <h2>Categories</h2>
        <div id="placeholder" style="width:788px;height:400px"></div>
        <h3>End of Page</h3>
</body>
</html>

目录结构如下root @ domU-12-31-39-13-C5-F5:/usr/local/jetty/webapps#树

Directory structure is as followsroot@domU-12-31-39-13-C5-F5:/usr/local/jetty/webapps# tree

.
|-- README.TXT
`-- ROOT
    |-- META-INF
    |   |-- MANIFEST.MF
    |   `-- maven
    |       `-- com.mkyong.common
    |           `-- SpringMVC
    |               |-- pom.properties
    |               `-- pom.xml
    |-- scripts
    |   |-- jquery.colorhelpers.js
    |   |-- jquery.flot.time.js
    |   |-- jquery.flot.time.min.js
    |   |-- jquery.js
    |   |-- jquery.min.js
    |   |-- LICENSE.txt
    |   |-- Makefile
    |   |-- NEWS.md
    |   |-- PLUGINS.md
    |   `-- README.md
    `-- WEB-INF
        |-- classes
        |   `-- com
        |       `-- mkyong
        |           `-- common
        |               `-- controller
        |                   `-- HelloController.class
        |-- hello.html
        |-- lib
        |   |-- aopalliance-1.0.jar
        |   |-- commons-logging-1.1.1.jar
        |   |-- spring-aop-3.0.5.RELEASE.jar
        |   |-- spring-asm-3.0.5.RELEASE.jar
        |   |-- spring-web-3.0.5.RELEASE.jar
        |   `-- spring-webmvc-3.0.5.RELEASE.jar
        |-- mvc-dispatcher-servlet.xml
        |-- pages
        |   |-- hello.html
        |   `-- hello.jsp
        `-- web.xml

观察

  1. 使用Firefox蚀,我可以看到浏览器正在请求 GET http://ec2-184-73-14-57.compute-1.amazonaws.com:5809/scripts/jquery.flot.js 但找不到它,因此失败并显示404未找到
  2. 将脚本目录移动到WEB-INF下并更改相对路径也会导致相同的错误.
  3. 部署在tomcat中的类似应用程序正在被引用为/scripts/*.js时从ROOT目录中选择.js文件
  4. 无法使用绝对路径引用js文件,当我这样做时,它将尝试将绝对路径附加到 http://ec2-184-73-14-57.compute-1.amazonaws.com:5809/并尝试获取它..从而导致404错误
  1. Using firefox eclipse, I can see that browser is requesting for GET http://ec2-184-73-14-57.compute-1.amazonaws.com:5809/scripts/jquery.flot.js but unable to find it hence fails with 404 Not found
  2. Moving the scripts directory to under WEB-INF and changing the relative paths is also resulting in the same error.
  3. Similar application deployed in tomcat is picking .js files from ROOT directory when referenced as /scripts/*.js
  4. Unable to reference the js files using absolute path and when I do, it tries to append the absolute path to http://ec2-184-73-14-57.compute-1.amazonaws.com:5809/ and trying to fetch it .. thus resulting in 404 error

以前从未使用过Jetty,这个问题是Jetty特有的吗?有什么更好的导入javascript文件的方法.请指教

Never used Jetty before, is this problem specific to Jetty? What is a better way to import javascript files. Please advice

这是webapp启动后的转储

Here is the dump after the start of the webapp

 2013-04-12 19:08:04.829:INFO:oejs.ServerConnector:main: Started ServerConnector@3ae0e5b7{HTTP/1.1}{0.0.0.0:5809}
    org.eclipse.jetty.server.Server@6a7ef378 - STARTING
     += qtp578065504{STARTED,10<=10<=200,i=8,q=0} - STARTED
     |   +- 12 qtp578065504-12-selector-0 RUNNABLE @ sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
     |   +- 13 qtp578065504-13-acceptor-0-ServerConnector@3ae0e5b7{HTTP/1.1}{0.0.0.0:5809} RUNNABLE @ sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
     |   +- 14 qtp578065504-14 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     |   +- 15 qtp578065504-15 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     |   +- 16 qtp578065504-16 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     |   +- 17 qtp578065504-17 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     |   +- 18 qtp578065504-18 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     |   +- 19 qtp578065504-19 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     |   +- 20 qtp578065504-20 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     |   +- 21 qtp578065504-21 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
     += org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@7c8b3bd8 - STARTED
     += org.eclipse.jetty.server.handler.HandlerCollection@582b0e7b - STARTED
     |   += org.eclipse.jetty.server.handler.ContextHandlerCollection@7e999262 - STARTED
     |   |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   |   += o.e.j.w.WebAppContext@2f7e1b09{/,file:/usr/local/osmosix/jetty/webapps/ROOT/,AVAILABLE}{/ROOT} - STARTED
     |   |       += org.eclipse.jetty.server.session.SessionHandler@8a6bf88 - STARTED
     |   |       |   += org.eclipse.jetty.server.session.HashSessionManager@3620f49e - STARTED
     |   |       |   += org.eclipse.jetty.security.ConstraintSecurityHandler@5daa3e56 - STARTED
     |   |       |   |   +- org.eclipse.jetty.security.DefaultAuthenticatorFactory@12959ac0
     |   |       |   |   += org.eclipse.jetty.servlet.ServletHandler@72140bcb - STARTED
     |   |       |   |   |   += default@5c13d641==org.eclipse.jetty.servlet.DefaultServlet,0,false - STARTED
     |   |       |   |   |   |   +- maxCacheSize=256000000
     |   |       |   |   |   |   +- etags=true
     |   |       |   |   |   |   +- dirAllowed=true
     |   |       |   |   |   |   +- gzip=true
     |   |       |   |   |   |   +- maxCachedFileSize=200000000
     |   |       |   |   |   |   +- redirectWelcome=false
     |   |       |   |   |   |   +- acceptRanges=true
     |   |       |   |   |   |   +- welcomeServlets=false
     |   |       |   |   |   |   +- aliases=false
     |   |       |   |   |   |   +- useFileMappedBuffer=true
     |   |       |   |   |   |   +- maxCachedFiles=2048
     |   |       |   |   |   +- [/]=>default
     |   |       |   |   |   += jsp@19c47==org.apache.jasper.servlet.JspServlet,0,false - STARTED
     |   |       |   |   |   |   +- logVerbosityLevel=DEBUG
     |   |       |   |   |   |   +- fork=false
     |   |       |   |   |   |   +- scratchdir=/tmp/jetty-0.0.0.0-5809-ROOT-_-any-/jsp
     |   |       |   |   |   |   +- xpoweredBy=false
     |   |       |   |   |   +- [*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp
     |   |       |   |   |   += mvc-dispatcher@f974527a==org.springframework.web.servlet.DispatcherServlet,1,true - STARTED
     |   |       |   |   |   +- [/]=>mvc-dispatcher
     |   |       |   |   |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   |       |   |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   |       |   |   +~ HashLoginService[Test Realm] - STARTED
     |   |       |   |   +- org.eclipse.jetty.security.DefaultIdentityService@77df3248
     |   |       |   |   +- org.eclipse.jetty.security.authentication.BasicAuthenticator@652520bb
     |   |       |   |   |
     |   |       |   |   +> HashLoginService[Test Realm] - STARTED
     |   |       |   |   +> org.eclipse.jetty.security.DefaultIdentityService@77df3248
     |   |       |   |   +> org.eclipse.jetty.security.authentication.BasicAuthenticator@652520bb
     |   |       |   |   +> []
     |   |       |   |   +> /={TRACE={RoleInfo,F,C[]}}
     |   |       |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   |       += org.eclipse.jetty.servlet.ErrorPageErrorHandler@4ec93402 - STARTED
     |   |       |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   |       +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   |       |
     |   |       +> WebAppClassLoader=Spring Web MVC Application@bf6140f
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/classes/
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-aop-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-beans-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-expression-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/aopalliance-1.0.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-context-support-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-web-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-core-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-webmvc-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-asm-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/spring-context-3.0.5.RELEASE.jar
     |   |       |   +- file:/usr/local/osmosix/jetty/webapps/ROOT/WEB-INF/lib/commons-logging-1.1.1.jar
     |   |       |   +- startJarLoader@518cb416
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-xml-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/servlet-api-3.0.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-http-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-continuation-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-server-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-security-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-servlet-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-webapp-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-deploy-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-client-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-jmx-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jsp/com.sun.el-2.2.0.v201108011116.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jsp/javax.el-2.2.0.v201108011116.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jsp/org.eclipse.jdt.core-3.7.1.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/resources/
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-api-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-common-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-server-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-servlet-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-util-9.0.0.v20130308.jar
     |   |       |       +- file:/usr/local/osmosix/jetty/lib/jetty-io-9.0.0.v20130308.jar
     |   |       |       +- sun.misc.Launcher$AppClassLoader@e9576fd
     |   |       |           +- file:/usr/local/osmosix/jetty/start.jar
     |   |       |           +- sun.misc.Launcher$ExtClassLoader@76b6e385
     |   |       +> contextConfigLocation=/WEB-INF/mvc-dispatcher-servlet.xml
     |   |       +> javax.servlet.context.tempdir=/tmp/jetty-0.0.0.0-5809-ROOT-_-any-
     |   |       +> org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern=.*/servlet-api-[^/]*\.jar$
     |   |       +> org.springframework.web.context.support.ServletContextScope=org.springframework.web.context.support.ServletContextScope@392e8f9
     |   |       +> org.springframework.web.context.WebApplicationContext.ROOT=Root WebApplicationContext: startup date [Fri Apr 12 19:08:03 UTC 2013]; root of context hierarchy
     |   |       +> org.springframework.web.servlet.FrameworkServlet.CONTEXT.mvc-dispatcher=WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Fri Apr 12 19:08:04 UTC 2013]; parent: Root WebApplicationContext
     |   += org.eclipse.jetty.server.handler.DefaultHandler@423dc560 - STARTED
     |   |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   += org.eclipse.jetty.server.handler.RequestLogHandler@70a6302b - STARTED
     |   |   += org.eclipse.jetty.server.NCSARequestLog@6dbe7935 - STARTED
     |   |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     += HashLoginService[Test Realm] - STARTED
     +- org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   +- org.eclipse.jetty.security.ConstraintSecurityHandler@5daa3e56=org.eclipse.jetty.security:context=ROOT,type=constraintsecurityhandler,id=0
     |   +- org.eclipse.jetty.security.DefaultAuthenticatorFactory@12959ac0=org.eclipse.jetty.security:context=ROOT,type=defaultauthenticatorfactory,id=0
     |   +- qtp578065504{STARTED,10<=10<=200,i=8,q=0}=org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0
     |   +- [*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp=org.eclipse.jetty.servlet:context=ROOT,type=servletmapping,name=jsp,id=0
     |   +- org.eclipse.jetty.server.Server@6a7ef378=org.eclipse.jetty.server:type=server,id=0
     |   +- org.eclipse.jetty.deploy.providers.WebAppProvider@3e9985a5=org.eclipse.jetty.deploy.providers:type=webappprovider,id=0
     |   +- HttpConnectionFactory@33192410{HTTP/1.1}=org.eclipse.jetty.server:context=HTTP/1.1@3ae0e5b7,type=httpconnectionfactory,id=0
     |   +- default@5c13d641==org.eclipse.jetty.servlet.DefaultServlet,0,false=org.eclipse.jetty.servlet:context=ROOT,type=servletholder,name=default,id=0
     |   +- org.eclipse.jetty.server.handler.DefaultHandler@423dc560=org.eclipse.jetty.server.handler:type=defaulthandler,id=0
     |   +- [/]=>default=org.eclipse.jetty.servlet:context=ROOT,type=servletmapping,name=default,id=0
     |   +- org.eclipse.jetty.server.handler.RequestLogHandler@70a6302b=org.eclipse.jetty.server.handler:type=requestloghandler,id=0
     |   +- org.eclipse.jetty.servlet.ServletHandler@72140bcb=org.eclipse.jetty.servlet:context=ROOT,type=servlethandler,id=0
     |   +- org.eclipse.jetty.server.handler.ContextHandlerCollection@7e999262=org.eclipse.jetty.server.handler:type=contexthandlercollection,id=0
     |   +- org.eclipse.jetty.server.session.HashSessionIdManager@434d3d4f=org.eclipse.jetty.server.session:type=hashsessionidmanager,id=0
     |   +- org.eclipse.jetty.jmx.MBeanContainer@3a55b9b=org.eclipse.jetty.jmx:type=mbeancontainer,id=0
     |   +- HashLoginService[Test Realm]=org.eclipse.jetty.security:type=hashloginservice,id=0
     |   +- jsp@19c47==org.apache.jasper.servlet.JspServlet,0,false=org.eclipse.jetty.servlet:context=ROOT,type=servletholder,name=jsp,id=0
     |   +- o.e.j.w.WebAppContext@2f7e1b09{/,file:/usr/local/osmosix/jetty/webapps/ROOT/,AVAILABLE}{/ROOT}=org.eclipse.jetty.webapp:context=ROOT,type=webappcontext,id=0
     |   +- HttpConfiguration@3636d04a{32768,8192/8192,https://:5809,[]}=org.eclipse.jetty.server:context=HTTP/1.1@3ae0e5b7,type=httpconfiguration,id=0
     |   +- org.eclipse.jetty.security.DefaultIdentityService@77df3248=org.eclipse.jetty.security:context=ROOT,type=defaultidentityservice,id=0
     |   +- org.eclipse.jetty.io.ArrayByteBufferPool@bba4cd7=org.eclipse.jetty.io:context=HTTP/1.1@3ae0e5b7,type=arraybytebufferpool,id=0
     |   +- sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:5809]=sun.nio.ch:context=HTTP/1.1@3ae0e5b7,type=serversocketchannelimpl,id=0
     |   +- org.eclipse.jetty.security.authentication.BasicAuthenticator@652520bb=org.eclipse.jetty.security.authentication:context=ROOT,type=basicauthenticator,id=0
     |   +- mvc-dispatcher@f974527a==org.springframework.web.servlet.DispatcherServlet,1,true=org.eclipse.jetty.servlet:context=ROOT,type=servletholder,name=mvc-dispatcher,id=0
     |   +- org.eclipse.jetty.server.session.SessionHandler@8a6bf88=org.eclipse.jetty.server.session:context=ROOT,type=sessionhandler,id=0
     |   +- [/]=>mvc-dispatcher=org.eclipse.jetty.servlet:context=ROOT,type=servletmapping,name=mvc-dispatcher,id=0
     |   +- org.eclipse.jetty.server.handler.HandlerCollection@582b0e7b=org.eclipse.jetty.server.handler:type=handlercollection,id=0
     |   +- org.eclipse.jetty.deploy.DeploymentManager@76bb5e95=org.eclipse.jetty.deploy:type=deploymentmanager,id=0
     |   +- org.eclipse.jetty.server.session.HashSessionManager@3620f49e=org.eclipse.jetty.server.session:context=ROOT,type=hashsessionmanager,id=0
     |   +- ServerConnector@3ae0e5b7{HTTP/1.1}{0.0.0.0:5809}=org.eclipse.jetty.server:context=HTTP/1.1@3ae0e5b7,type=serverconnector,id=0
     |   +- org.eclipse.jetty.util.log.Log@3daf611c=org.eclipse.jetty.util.log:type=log,id=0
     |   +- org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@3b195903=org.eclipse.jetty.server:context=HTTP/1.1@3ae0e5b7,type=serverconnector$serverconnectormanager,id=0
     |   +- org.eclipse.jetty.servlet.ErrorPageErrorHandler@4ec93402=org.eclipse.jetty.servlet:context=ROOT,type=errorpageerrorhandler,id=0
     |   +- org.eclipse.jetty.server.NCSARequestLog@6dbe7935=org.eclipse.jetty.server:type=ncsarequestlog,id=0
     |   +- org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@7c8b3bd8=org.eclipse.jetty.util.thread:type=scheduledexecutorscheduler,id=0
     +- org.eclipse.jetty.util.log.Log@3daf611c
     += ServerConnector@3ae0e5b7{HTTP/1.1}{0.0.0.0:5809} - STARTED
     |   +~ org.eclipse.jetty.server.Server@6a7ef378 - STARTING
     |   +~ qtp578065504{STARTED,10<=10<=200,i=8,q=0} - STARTED
     |   +~ org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@7c8b3bd8 - STARTED
     |   +- org.eclipse.jetty.io.ArrayByteBufferPool@bba4cd7
     |   += HttpConnectionFactory@33192410{HTTP/1.1} - STARTED
     |   |   +- HttpConfiguration@3636d04a{32768,8192/8192,https://:5809,[]}
     |   |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   += org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@3b195903 - STARTED
     |   |   +- org.eclipse.jetty.io.SelectorManager$ManagedSelector@6436babd keys=0 selected=0 id=0
     |   |       +- org.eclipse.jetty.io.SelectorManager$ManagedSelector.select(SelectorManager.java:443)
     |   |       +- sun.nio.ch.EPollSelectorImpl@27f703ba keys=0
     |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     |   +- sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:5809]
     += org.eclipse.jetty.deploy.DeploymentManager@76bb5e95 - STARTED
     |   +~ org.eclipse.jetty.deploy.providers.WebAppProvider@3e9985a5 - STARTED
     |   +~ org.eclipse.jetty.jmx.MBeanContainer@3a55b9b
     += org.eclipse.jetty.server.session.HashSessionIdManager@434d3d4f - STARTED
     |
     +> startJarLoader@518cb416
         +- file:/usr/local/osmosix/jetty/lib/jetty-xml-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/servlet-api-3.0.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-http-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-continuation-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-server-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-security-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-servlet-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-webapp-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-deploy-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-client-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-jmx-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jsp/com.sun.el-2.2.0.v201108011116.jar
         +- file:/usr/local/osmosix/jetty/lib/jsp/javax.el-2.2.0.v201108011116.jar
         +- file:/usr/local/osmosix/jetty/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
         +- file:/usr/local/osmosix/jetty/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar
         +- file:/usr/local/osmosix/jetty/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar
         +- file:/usr/local/osmosix/jetty/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar
         +- file:/usr/local/osmosix/jetty/lib/jsp/org.eclipse.jdt.core-3.7.1.jar
         +- file:/usr/local/osmosix/jetty/resources/
         +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-api-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-common-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-server-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/websocket/websocket-servlet-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-util-9.0.0.v20130308.jar
         +- file:/usr/local/osmosix/jetty/lib/jetty-io-9.0.0.v20130308.jar
         +- sun.misc.Launcher$AppClassLoader@e9576fd
             +- file:/usr/local/osmosix/jetty/start.jar
             +- sun.misc.Launcher$ExtClassLoader@76b6e385

推荐答案

您的servlet-mapping设置不正确.

名为mvc-dispatcher的servlet是在"/"url-pattern处设置的,也称为servlet规范默认servlet路径规范. Web容器本身提供的一些功能使其可以提供静态内容(例如CSS和javascript文件).

The servlet named mvc-dispatcher is setup at url-pattern of "/", also known as the servlet spec default servlet path spec. Something that the web container itself provides to allow it to serve static content (like css and javascript files).

mvc-dispatcher位于"/",这意味着默认Servlet本身不能提供静态内容.

With your mvc-dispatcher at "/" that means the Default Servlet itself cannot serve static content.

这也意味着org.springframework.web.servlet.DispatcherServlet现在负责提供来自WebApp的所有内容.这是一个非典型的servlet-mapping,我怀疑这就是spring DispatcherServlet的作用.

That also means that org.springframework.web.servlet.DispatcherServlet is now responsible for serving all content from the WebApp. This is an atypical servlet-mapping and I doubt that's the role of the spring DispatcherServlet.

考虑使用基于后缀的servlet路径规范(例如"*.html")或基于前缀的servlet路径规范(例如"/*")(在Servlet规范的第12节中对此进行了概述)

Consider using a suffix based servlet path spec like "*.html" or a prefix based servlet path spec like "/*" (this is outlined in the Section 12 of the Servlet Spec)

这篇关于无法在Jetty Web应用程序中加载Java脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:14