Spring MVC 4:静态内容映射有时有时不起作用

时间:2014-09-27 20:55:44

标签: spring spring-mvc

我试图从最近几个小时解决这个问题..但没有运气。

我有以下两种方法:

@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(RegistrationForm registrationDetails){
    logger.info("Inside POST /register method");
    return "register";
}

@RequestMapping(value = "/register", method = RequestMethod.GET)
public String showRegister(@RequestParam(value="name", required=true) String name, Model model){
    return "register";
}

正如您所看到的,我正在尝试从这两种方法中呈现相同的html页面。

问题:当我做GET时,我看到我的网页完全没问题。但是当我执行POST并再次返回相同的html时,我的css,js和图像根本不会渲染。我不知道这些文件的路径是如何搞砸的。

我试图应用我在网上找到的许多解决方案。但没有运气。 我得到以下错误:

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/registers/resources/themes/css/bootstrap-responsive.min.css] in DispatcherServlet with name 'appServlet'
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/registers/resources/themes/bootshop/bootstrap.min.css] in DispatcherServlet with name 'appServlet'
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/registers/resources/themes/images/payment_methods.png] in DispatcherServlet with name 'appServlet'

我引用这些资源的HTML代码:

<link rel="shortcut icon" href="resources/themes/images/ico/favicon.ico"></link>
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="resources/themes/images/ico/apple-touch-icon-144-precomposed.png"></link>
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="resources/themes/images/ico/apple-touch-icon-114-precomposed.png"></link>
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="resources/themes/images/ico/apple-touch-icon-72-precomposed.png"></link>

这是我的servlet-context.xml

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<resources mapping="/resources/**" location="/resources" />

<beans:bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    <beans:property name="templateEngine" ref="templateEngine" />
    <beans:property name="order" value="1" />
    <beans:property name="viewNames" value="*.html,*.xhtml" />
</beans:bean>

<beans:bean id="templateResolver"
    class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".html" />
    <beans:property name="templateMode" value="HTML5" />
</beans:bean>

<beans:bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
    <beans:property name="templateResolver" ref="templateResolver" />
</beans:bean>

<beans:bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    <beans:property name="templateEngine" ref="templateEngine" />
</beans:bean>

我的文件夹结构是:

Directory structure

我看到很多人在类似的问题中展示他们的目录结构,所以我也在展示它。

0 个答案:

没有答案