Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Professional Java for Web Applications
|
BOOK: Professional Java for Web Applications
This is the forum to discuss the Wrox book Professional Java for Web Applications by Nicholas S. Williams; ISBN: 978-1-118-65646-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Java for Web Applications section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2018, 10:07 AM
Registered User
 
Join Date: Apr 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default CharacterEncoding DispatcherServlet Spring Boot MVC Response jsp

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??

The controller which send input to the jsp:

Code:
@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:

Code:
<%@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>
        <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):

Code:
@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;
    }
}

Last edited by [email protected]; April 4th, 2018 at 10:13 AM.. Reason: format change





Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors while upgrade theBeerHouse mvc project form asp.net mvc 1.0 to 2.0 vanbach1304 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 0 April 20th, 2010 06:43 AM
TheBeerHouse MVC preview ASP.NET MVC Website Programming Problem Design Solution jminatel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 July 18th, 2009 09:16 AM
Program a boot software rameshg87 Assembly Language 1 February 21st, 2007 12:18 PM
Dual Boot - Windows TonyG Linux 3 December 28th, 2005 10:56 AM
Boot loader for dual-boot system? cox100 Linux 2 February 4th, 2004 06:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.