我的Maven WebApp项目具有以下文件夹结构
src
+-----main
+-----java
| +-----com
| +------controller
| +-----HomeController.java
|
+-----resources
+-----webapp
+-----resources
| +-----css
| +-----home.css
+-----WEB-INF
+-----jsp
| +------home.jsp
+-----eLibrary-servlet.xml
+-----web.xml
web.xml:
<servlet>
<servlet-name>eLibrary</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>eLibrary</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<display-name>eLibrary</display-name>
eLibrary-servlet.xml:
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEF-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources location="/resources/" mapping="/resources/**" />
HomeController.java:
@Controller
public class HomeController {
@RequestMapping("/")
public String getHomePage() {
return "home";
}
}
在home.jsp中,我试图使用${pageContext.request.contextPath}/resources/css/home.css
但是我的JSP文件(即home.jsp)和CSS文件(即home.css)都没有加载到浏览器中,并且在对http://localhost:8080/eLibrary/进行消息访问时,我的HTTP状态为404
/eLibrary/WEF-INF/jsp/home.jsp
和说明
原始服务器找不到目标资源的当前表示,或者不愿意透露其存在。
答案 0 :(得分:1)
您在这里/WEF-INF/jsp/
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEF-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
将其更改为/WEB-INF/jsp/
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
答案 1 :(得分:0)
在配置Spring DispatcherServlet中有一个错误。您需要在 web.xml 中提及您的 eLibrary-servlet.xml 。需要按照下面的链接中所述重新排列web.xml。
https://docs.spring.io/spring-flex/docs/1.0.x/reference/html/ch02s02.html
<?php
echo dateDiff("2018-01-01","2018-12-31");
// OR
$firstDate = "2018-01-01";
$secondDate = "2018-01-01";
echo dateDiff($firstDate,$secondDate);
?>
希望这很有用。
答案 2 :(得分:0)
elibrary-servlet.xml中有拼写错误
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources location="/resources/" mapping="/resources/**" />