【发布时间】:2014-04-12 03:06:02
【问题描述】:
好的,所以一段时间以来,我一直在尝试设置与 DOJO 集成的 Spring MVC 项目。终于决定是时候在这里做一个帐户并提出问题了。除了我从标签引用的 dojo.js 文件之外,我已经加载了所有内容。我将提供我的项目层次结构和我所看到的:
我的@RequestMapping 方法。
@RequestMapping(value = "/rbd", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home";
}
..当我浏览到http://localhost:8080/myproject/rbd 时,应用程序正在成功加载 home.jsp 文件,如下所示:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page session="false"%>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
<link rel="icon" href="../sba-icon.png" type="image/x-icon" />
<link rel="shortcut icon" href="../sba-icon.png" type="image/x-icon" />
<script src="<spring:url value='/scripts/dojo/dojo.js'/>" data-dojo-config:"locale:'en', async:true, parseOnLoad:false"></script>
..我的 JBOSS 部署文件夹遵循 myproject/scripts/dojo/dojo.js 的层次结构。我的 home.jsp 在 myproject/WEB-INF/views/home.jsp 中。 src 标记的位置是否相对于 home.jsp 的位置?我很迷茫,因为我不断收到 404 错误。但我显然知道 dojo.js 在服务器上。我已经尝试了每条对我有意义的路径,我是 Spring/MVC 初学者,所以请不要抨击!
感谢您的帮助! :)
编辑:这是我在 web.xml 中的 DispatcherServlet 的初始化 ...
<servlet>
<servlet-name>rbd</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/rbd/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rbd</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
..这是我的 servlet-context.xml,位于上面显示的路径中..
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
【问题讨论】:
-
您的
DispatcherServlet映射到什么位置? -
抱歉 Sotirios,我是 Spring 新手,所以我不确定你在问什么。我使用帖子底部的 DispatcherServlet 信息编辑了原始帖子。
-
由于您有一个映射到
/resources的资源处理程序,请将您的scripts放入/resources并相应地访问它。 -
不确定您的意思。我在资源文件夹中链接了我构建的脚本文件夹,仍然得到 404
-
edit:: 所以我将映射更改为
然后我不再得到 404!还有更多问题需要解决,但我想这对于第一次项目设置来说是正常的
标签: html spring model-view-controller dojo http-status-code-404