I'm using a Spring Boot MVC startup, with using DispatcherServlet. I understand, that there are many implementations of it. The problem is, when a form with a POST (with a choice of Footbal CLubs with different characters like ü, ë, è are chosen), these are not well responded to the Controller. I use in the jsp's UTF-8, I guess everywhere (RootContext, tomcat (maybe not), jsp's the character encoding is set to UTF-8. So, the problem is, how do I change the character-encoding for my response??
I can add a lot of sources, if you want or need ....
The controller which send input to the jsp:
@RequestMapping(value = "zoekenclubsduels", method = RequestMethod.POST)
public ModelAndView tonenVanClub(@RequestParam("land1") String land1, @RequestParam("land2") String land2) {
LocalDate ld = LocalDate.now();
String contextPath = context.getContextPath();
List<Club> clubs1 = this.clubManager.getAllByClland(land1);
if (clubs1 == null) {
return new ModelAndView("redirect:/clubs/zoekenlandenduels");
}
Collections.sort(clubs1);
List<Club> clubs2 = this.clubManager.getAllByClland(land2);
if (clubs2 == null) {
return new ModelAndView("redirect:/clubs/zoekenlandenduels");
}
Collections.sort(clubs2);
ModelAndView modelAndView = new ModelAndView("clubs/zoekenclubsduels");
modelAndView.addObject("clubs1", clubs1);
modelAndView.addObject("clubs2", clubs2);
modelAndView.addObject("contextPath", contextPath);
modelAndView.addObject("ld", ld);
return modelAndView;
}
The jsp:
<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="contextPath"
value="${pageContext.servletContext.contextPath}" />
<!doctype html>
<html lang="nl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Select Clubs</title>
<link rel="stylesheet" href="<c:url value="/styles/reset.css"/>" />
<link rel="stylesheet" href="<c:url value="/styles/default.css"/>" />
<link rel="stylesheet" href="<c:url value="/styles/responsive.css" />" />
<link rel="stylesheet" href="<c:url value="/styles/menu.css" />" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">window.jQuery|| document
.write('<script type="text/javascript" src="/EuropeanCupFootball\/scripts\/vendor\/1.7.2.jquery.min.js"><\/script>')
</script>
<script src="${contextPath}/scripts/vendor/jquery.slides.min.js"></script>
<script src="${contextPath}/scripts/scriptslidejs.js"></script>
<script src="${contextPath}/scripts/script_menu.js"></script>
<!-- script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script-->
</head>
<body>
<!-- body style="background-image: url(${contextPath}/images/page_bg.jpg)"-->
<header>
<c:import url="/WEB-INF/jsp/header.jsp" />
</header>
<br>
<h2>Select Clubs for mutual Results</h2>
<br> <br>
<div class="pageczld">
<c:if test="${not empty clubs1}">
<form action="<c:url value='/clubs/toonuitslagenduels'/>"
method="post">
<label>Club 1 : <select required name="club1" size="15">
<c:forEach items="${clubs1}" var="club1">
<option value="${club1.clNaam}"
${club1.clNaam == param.club1.clNaam ? 'selected="selected"' : ''}>
${club1.clNaam}</option>
</c:forEach>
</select>
</label> <label>Club 2 : <select required name="club2" size="15">
<c:forEach items="${clubs2}" var="club2">
<option value="${club2.clNaam}"
${club2.clNaam == param.club2.clNaam ? 'selected="selected"' : ''}>
${club2.clNaam}</option>
</c:forEach>
</select>
</label> <input type="submit" value="OK" /> ${fout}
</form>
</c:if>
</div>
<footer>
<c:import url="/WEB-INF/jsp/footer.jsp" />
</footer>
<div style="clear: both;"></div>
</body>
</html>
The controller which receives output from jsp (java):
@RequestMapping(value = "toonuitslagenduels", method = RequestMethod.POST)
public ModelAndView toonUitslagenDuels(@RequestParam("club1") String club1string,
@RequestParam("club2") String club2string) {
// List<UitslagClub> uitslagclubs =
// this.clubManager.getByClNaamUitslagclubs(clubstring);
LocalDate ld = LocalDate.now();
String contextPath = context.getContextPath();
Club clubByName1 = this.clubManager.getByClNaam(club1string);
Club club1 = this.clubManager.getOne(clubByName1.getClNr());
if (club1 == null) {
return new ModelAndView("redirect:/clubs/zoekenlandenduels");
}
Club clubByName2 = this.clubManager.getByClNaam(club2string);
Club club2 = this.clubManager.getOne(clubByName2.getClNr());
if (club2 == null) {
return new ModelAndView("redirect:/clubs/zoekenlandenduels");
}
List<Uitslag> uitslagen = new ArrayList<Uitslag>();
List<UitslagClub> uitslagclubs = new ArrayList<UitslagClub>();
List<UitslagClub> uitslagclub1 = club1.getUitslagclubs();
List<UitslagClub> uitslagclub2 = club2.getUitslagclubs();
Iterator<UitslagClub> iter1 = uitslagclub1.iterator();
while (iter1.hasNext()) {
UitslagClub uc1 = (UitslagClub) iter1.next();
Iterator<UitslagClub> iter2 = uitslagclub2.iterator();
while (iter2.hasNext()) {
UitslagClub uc2 = (UitslagClub) iter2.next();
if (uc2.getUcUiNr() == uc1.getUcUiNr()) {
Uitslag uitslag = this.uitslagManager.getUitslag(uc2.getUcUiNr());
uitslagen.add(uitslag);
uitslagclubs.add(uc1);
}
}
}
int awed = 0;
int awinst = 0;
int agelijk = 0;
int averlies = 0;
int dpvoor = 0;
int dptegen = 0;
Iterator<UitslagClub> ucIter = uitslagclubs.iterator();
while (ucIter.hasNext()) {
UitslagClub uc = ucIter.next();
awed++;
if (uc.getUcThuisOfUit().equals("t")) {
if (uc.getUitslag().getUiThDoelpunten() > uc.getUitslag().getUiUitDoelpunten()) {
awinst++;
dpvoor = dpvoor + uc.getUitslag().getUiThDoelpunten();
dptegen = dptegen + uc.getUitslag().getUiUitDoelpunten();
}
else if (uc.getUitslag().getUiThDoelpunten() == uc.getUitslag().getUiUitDoelpunten()) {
agelijk++;
dpvoor = dpvoor + uc.getUitslag().getUiThDoelpunten();
dptegen = dptegen + uc.getUitslag().getUiUitDoelpunten();
}
else {
averlies++;
dpvoor = dpvoor + uc.getUitslag().getUiThDoelpunten();
dptegen = dptegen + uc.getUitslag().getUiUitDoelpunten();
}
}
else {
if (uc.getUitslag().getUiThDoelpunten() < uc.getUitslag().getUiUitDoelpunten()) {
awinst++;
dpvoor = dpvoor + uc.getUitslag().getUiUitDoelpunten();
dptegen = dptegen + uc.getUitslag().getUiThDoelpunten();
}
else if (uc.getUitslag().getUiThDoelpunten() == uc.getUitslag().getUiUitDoelpunten()) {
agelijk++;
dpvoor = dpvoor + uc.getUitslag().getUiThDoelpunten();
dptegen = dptegen + uc.getUitslag().getUiUitDoelpunten();
}
else {
averlies++;
dpvoor = dpvoor + uc.getUitslag().getUiUitDoelpunten();
dptegen = dptegen + uc.getUitslag().getUiThDoelpunten();
}
}
}
if (uitslagen.isEmpty()) {
ModelAndView modelAndView = new ModelAndView("clubs/geenuitslagenduels", "contextPath", contextPath);
modelAndView.addObject("ld", ld);
modelAndView.addObject("club1", club1);
modelAndView.addObject("club2", club2);
return modelAndView;
} else {
int aantalUitslagen = uitslagen.size();
ModelAndView modelAndView = new ModelAndView("clubs/toonuitslagenduels", "uitslagen", uitslagen);
modelAndView.addObject("contextPath", contextPath);
modelAndView.addObject("ld", ld);
modelAndView.addObject("aantalUitslagen", aantalUitslagen);
modelAndView.addObject("club1", club1);
modelAndView.addObject("club2", club2);
modelAndView.addObject("awed", awed);
modelAndView.addObject("awinst", awinst);
modelAndView.addObject("agelijk", agelijk);
modelAndView.addObject("averlies", averlies);
modelAndView.addObject("dpvoor", dpvoor);
modelAndView.addObject("dptegen", dptegen);
return modelAndView;
}
}