[英]Adding css and js to Spring project
我知道这个问题在stackoverflow上已经回答了很多次,但是我不能按照答案的步骤来解决。
首先,我要添加一些静态文件(css js img)到我的项目中,以便从html标签访问它们。
我的项目结构是:
http://i.stack.imgur.com/5bfVu.jpg
我的项目在添加CSS之前工作正常,但是我读了其他文章,应该将此行添加到调度程序文件中:
<mvc:resources mapping="/**" location="/jsp/website/" />
但是,当我添加它时,我无法再部署并得到此错误:
GlassFish Server, deploy, null, false
注意 :
我更改了配置文件中的某些内容,以从URL中删除.htm扩展名。
我的调度员:
<mvc:resources mapping="/**" location="/" />
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="indexContr"/>
我的web.xml文件:
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
谢谢你的帮助。
您已将可用于调度程序servlet的所有名称空间映射为资源。 将其从/ **减少到/ jsp / website / **
<mvc:resources mapping="/resources/**" location="/jsp/website/" />
我建议您不要将静态资源保留在/ jsp /下,这应该是jsp的=)在路径中使用“ static”或“ resources”
<mvc:resources mapping="/resources/**" location="/resources/" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.