【发布时间】:2015-10-15 09:11:41
【问题描述】:
我知道这个问题在 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>
感谢您的帮助。
【问题讨论】:
-
您检查过服务器日志是否有任何异常?部署失败很奇怪。请检查 Your_GlassFish_Location\glassfish\domains\domain1\logs\server.log
标签: java css xml spring spring-mvc