[英]Spring MVC integration js and css files
I'm new with Spring Framework, this is my first app using it, so, I have the next problem.. And I'm sorry for my really bad english hehe.. 我是Spring Framework的新手,这是我第一个使用它的应用程序,所以,我有下一个问题。.对不起,我的英语不好。
I need to include in my jsp some js and css files. 我需要在我的jsp中包含一些js和css文件。 I'm working with spring mvc.
我正在使用Spring MVC。 I have a NotClassFound exception.. This is all my code:
我有一个NotClassFound异常。这是我的全部代码:
In my web.xml 在我的web.xml中
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.springframework.js.resource.ResouceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
In servlet-context (I've tried with mvc resource with and without "classpath") 在servlet上下文中(我尝试使用带有和不带有“类路径”的mvc资源)
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<mvc:default-servlet-handler />
<!-- <mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/"/> -->
<mvc:resources mapping="/resources/**" location="/resources/" />
in the jsp file 在jsp文件中
<%@ page import="org.springframework.js.resource.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="<c:url value='/resources/medico.css'/>" />
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/zapdent.js"></script>
<%-- <script type="text/javascript" src="<c:url value="/resources/spring/Spring-Dojo.js" />"> </script> --%>
</head>
In 'webapp/resources' is where I have my js and ccs files.. and I think my principal problem is with the org.springframework.js library.. I'm mapping it in the web.xml, but when I run the project I have this: 在“ webapp / resources”中,我有我的js和ccs文件..我认为我的主要问题是与org.springframework.js库有关。我正在将其映射到web.xml中,但是当我运行项目我有这个:
SEVERE: Servlet /springsecurity threw load() exception
java.lang.ClassNotFoundException: org.springframework.js.resource.ResouceServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1295)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1147)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:520)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:501)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:120)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4944)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I have like a week trying to figure out this problem, but I dont know how to do it.. Please, I need help! 我有一个星期想弄清楚这个问题,但是我不知道该怎么办..请,我需要帮助!
Looking at web.xml it seems that org.springframework.js.resource.ResouceServlet
should be there, but make sure it exists in the classpath. 查看web.xml,似乎
org.springframework.js.resource.ResouceServlet
应该存在,但请确保它存在于类路径中。 You could also try following this link and perform these steps: 您也可以尝试点击此链接并执行以下步骤:
https://stackoverflow.com/a/28170853/2748793 https://stackoverflow.com/a/28170853/2748793
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.