每当用户在 url 中输入无效 ID 时,我都会尝试显示 404。
def show(Hero heroInstance) {
if (heroInstance == null) {
notFound()
return response.sendError(404)
}
respond heroInstance
}
404 映射到 UrlMappings 中的自定义 page_not_found。但是,没有任何 css 被加载到页面中。我得到的只是一个带有页面未找到文本的页面。
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta name="layout" content="main">
<title>PAGE NOT FOUND</title>
</head>
<body>
<h2>404</h2>
<p>
PAGE NOT FOUND
</p>
</body>
</html>
有什么方法可以使用 sendError 加载 css 吗?
最佳答案
好吧,如果你有一个外部 CSS,我认为你应该添加
<link rel="stylesheet" href="css/style.css" media="all" />
给你的
<head></head>
只有这样你的 css 才会包含到你的 html 中
或
您可以在 html 页面本身中使用您的 css
<style>
your css goes here
</style>
关于html - Grails response.sendError 不渲染 gsp 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22552950/