我们在学校项目中遇到 jsp 形式的变音符号问题。我们使用 Spring 3.0。在 JSP 形式中,我们的输入可以包含带有变音符号的单词(捷克语,fe "šáříěá")。当我开始项目并将变音符号写入这些输入并发送表单时,控制器中立即出现错误值。变音字母有奇怪的形式,例如“Ä???Ä”。以下代码是我们的表单。
<%@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>
这是控制器:
@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 在控制台上写入奇怪的值。知道问题出在哪里吗?我想说的是,我们对 Java Web 编程有一点经验。谢谢