0

we have problem with diacritic in jsp form in school project. We use Spring 3.0. In JSP form we have inputs which can contains words with diacritic (czech language,f.e "šáříěá"). When I start project and write diacritic words into these inputs and send form, immediately in controller are wrong values. Diacritic letters has strange form, for example "Ä???Ä". Following code is our form.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Nový prostor</title>
</head>
<body>
    <h1>Nový prostor</h1>
     <form:form  method="POST" commandName="PLACE" >
        <fieldset>
            <legend>Adresa prostoru</legend>
            <table>
                <tr>
                    <td><form:label path="name">Název prostoru</form:label></td>
                    <td><form:input path="name" /></td>
                </tr>
                <tr>
                    <td><form:label path="street">Ulice a č.p.</form:label></td>
                    <td><form:input path="street" /></td>
                </tr>    
                <tr>
                    <td><form:label path="zip_code">PSČ</form:label></td>
                    <td><form:input path="zip_code" /></td>
                </tr>
                <tr>
                    <td><form:label path="city">Město</form:label></td>
                    <td><form:input path="city" /></td>
                </tr>
            </table>
        </fieldset>
        <fieldset>
            <legend>Parametry prostoru</legend>
            <table>
                <tr>
                    <td><form:label path="rows">Počet řad</form:label></td>
                    <td><form:input path="rows" /></td>
                </tr>
                <tr>
                    <td><form:label path="columns">Počet sedaček v řadě</form:label></td>
                    <td><form:input path="columns" /></td>
                </tr>    
                <tr>
                    <td><form:label path="note">Poznámky</form:label></td>
                    <td><form:textarea path="note" /></td>
                </tr>
            </table>
        </fieldset>  
        <input type="submit" value="Vytvořit">     
    </form:form>
</body>

And this is conroller:

@Controller
@RequestMapping("/newPlace")
public class NewPlaceController {
@Autowired
private PlaceService placeService;
/**
 * Pri pozadavku typu get vrati nazev jsp ktere se ma renderovat, nabinduje Complex place do formualre
 * @param model
 * @return
 */
@RequestMapping(method=RequestMethod.GET)
public String showNewPlaceForm(Model model){
    model.addAttribute("PLACE", new ComplexPlace());

    return "newPlaceForm";
}
/**
 *Pri pozadavku POST ulozi data z formulare do DB
 * 
 * @param place
 * @param result
 * @return
 */
@RequestMapping(method=RequestMethod.POST)
public String createNewPlace(@ModelAttribute(value="PLACE") ComplexPlace place, BindingResult result){
    System.out.println(place.getName());
    placeService.buildPlaceService(place);
    placeService.PersistNewPlace();
    return "/index";
}

}

System.out.println write strange value on console. Know somebody where is problem? I want remark, that we have small expirience with Java web programming. Thanks

Ondřej Ryška
  • 461
  • 1
  • 11
  • 23
  • 2
    Are you persisting this values to database? If yes then check if values are correct in database, because `System.out` might not print them in UTF-8. Also what application server are you using? – Aleksandr M Dec 07 '12 at 16:59
  • Yes, data are persist. We use Hibernate. Applicaton server is GlassFish 3+. Data in database are wrong too. But diacritic values in database are different that in console, but wrong too. Is possible, that setting of database is wrong and we must repair it. But I don't know why in console is wrong text. I must try save value in text file, provided is possible that System.out.println() can't print UTF-8. – Ondřej Ryška Dec 07 '12 at 17:37
  • 1
    Actually you do not need console, right? You are just using it to check values? If so then forget about console and fix your database encoding. – Aleksandr M Dec 07 '12 at 21:30
  • Yes, I use console only for check. Now I want repair database.. – Ondřej Ryška Dec 07 '12 at 21:36

1 Answers1

0

you can't use any other language other then standard english.if you want to do this then u have to use any standard free unicode converter.convert your character and put their unicode character at run time it is converted in your original language...i hope it works for you.

meet patel
  • 181
  • 1
  • 2
  • 17
  • I not solve console now, because System.ou.print() can have problem with UTF-8. Now I want solve database setting. Is your answer related with inserting into database or your tip si about console output only? I am sorry for stupid question:-) – Ondřej Ryška Dec 08 '12 at 12:31
  • This problem is solved:-). http://stackoverflow.com/questions/11758094/hibernate-encodes-wrong-while-persisting-objects-utf-8 – Ondřej Ryška Dec 08 '12 at 20:02