我在浏览工作时遇到了问题我似乎无法找到解决方案。
问题是我有一个互联网应用程序,它在Windows和Mac上正确显示(使用其他浏览器而不是safari)但是它不能在Safari上呈现(对于Mac用户)并且它不会在所有浏览器在使用iPhone时都可以使用。
我尝试添加
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
行,也在我的网络控制器上,我有这个:
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "text/html");
我仍然可以看到HTML代码本身而不是显示渲染页面。
在这里,您可以查看我的HTML代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{/css/custom.css}"
href="../../custom.css" />
</head>
<body>
<div class="content">
<img alt="" th:src="@{/img/logo.gif}" />
<h1>Hello </h1>
<h2>Some other text
</h2>
<form action="/confirm" method="POST" class="form">
<div th:if="${variable1==true}"><input type="checkbox" name="variable1"/>Option 1</div>
<div th:if="${variable2==true}"><input type="checkbox" name="variable2"/>Option 2</div>
<div th:if="${variable3==true}"><input type="checkbox" name="variable3"/>Option 3</div>
<div><input type="submit" value="Send" /></div>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
<input type="hidden" th:name="id" th:value="${id}" />
</form>
</div>
</body>
</html>
这是我的控制器获取方法:
@RequestMapping(method = RequestMethod.GET)
public String home(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "text/html");
System.out.println(response.getContentType());//Verifying this has been set
String id = request.getParameter("id");
try {
if(id==null) throw new Exception("Error del ID");
List<Boolean> yesOrNo = icfi.getSiONo(id);
model.put("variable1", yesOrNo.get(0));
model.put("variable2", yesOrNo.get(1));
model.put("variable3", yesOrNo.get(2));
model.put("id", id);
return "index";
} catch (Exception e) {
return "error";
}
}
我不知道它是否相关,但是我使用百里香(如果你发现th:属性令人不安)和Spring。
我在属性文件名application.properties上添加了一些文本:
#application.thymeleaf.templatesdir is relative to application path
application.thymeleaf.templatesdir = resources/templates/
application.thymeleaf.cache = false
#Undertow seems to read files only in Windows-1252 enconding.
application.thymeleaf.encoding = Windows-1252
application.thymeleaf.mode = HTML5
application.thymeleaf.content-type = text/html # ;charset=<encoding> is added
application.thymeleaf.suffix = .html