В моем весеннем проекте, который использует шаблон "Динамический веб-проект" из Eclipse, я использую как bootstrap, так и jquery-ui для создания представлений. Я поместил оба в папку WebContent моего проекта.
Я включаю необходимые файлы из этих библиотек следующим образом:
<!-- Bootstrap core CSS -->
<link href="<c:out value="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css"/>" rel="stylesheet">
<link href="<c:out value="${pageContext.request.contextPath}/bootstrap/css/bootstrap-theme.min.css"/>" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="<c:out value="/jquery-ui-1.10.4.custom.min.css"/>" rel="stylesheet">
<link href="<c:out value="${pageContext.request.contextPath}/extras/css/starter-template.css"/>" rel="stylesheet">
<link href="<c:out value="${pageContext.request.contextPath}/extras/css/grid.css"/>" rel="stylesheet">
<link href="<c:out value="${pageContext.request.contextPath}/extras/css/signin.css"/>" rel="stylesheet">
<link href="<c:out value="${pageContext.request.contextPath}/extras/css/table.css"/>" rel="stylesheet">
<link href="<c:out value="${pageContext.request.contextPath}/extras/css/responsible_table.css"/>" rel="stylesheet">
<link href="<c:out value="${pageContext.request.contextPath}/extras/css/style.css"/>" rel="stylesheet">
<link href="/normalize.css" rel="stylesheet" type="text/css"/>
<link href="/datepicker.css" rel="stylesheet" type="text/css"/>
<link href="/jquery-ui-timepicker-addon.min.css" rel="stylesheet" type="text/css"/>
и сопоставил их в моем классе WebAppConfig.java следующим образом:
@EnableWebMvc
@EnableTransactionManagement(mode=AdviceMode.PROXY, proxyTargetClass=true)
@ComponentScan(value="com.horariolivre")
@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/bootstrap/**").addResourceLocations("/bootstrap/").setCachePeriod(31556926);
registry.addResourceHandler("/extras/**").addResourceLocations("/extras/").setCachePeriod(31556926);
registry.addResourceHandler("/jquery/**").addResourceLocations("/jquery/").setCachePeriod(31556926);
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Это частично работает, поскольку WebApp не может читать значки из jquery-ui, вызывая сбои в отображении некоторых виджетов, которые я использую в своих представлениях, например, диалоговое окно jquery-ui, которое неправильно отображает кнопку закрытия.
У кого-нибудь есть идея, почему это происходит и как это исправить?
Я надеюсь, что это ваш проект: https://github.com/klebermo/maven_example/ :)
Проблема:
<!-- Custom styles for this template --><link href="<c:out value="/jquery-ui-1.10.4.custom.min.css"/>" rel="stylesheet">
Ваш путь неправильный -
value="/jquery-ui-1.10.4.custom.min.css"
Должен быть -
value="/jquery-ui-1.10.4.custom.min.css"
В случае его проскальзывания вы также ссылаетесь как на разработку, так и на мини-версии той же таблицы стилей.