Java入門–setCharacterEncodingでJSPのPOST処理で文字化けを防ぐ

1.JavaBeanコード
public class UserBean {
private String name;

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
2.register.html
<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title>会員登録</title>
</head>
<body>
<form action=”userReg.jsp” method=”post”>
<table>
<tr>
<td>ユーザID:<input type=”text” name=”name”></td>
<td><input type=”submit” value=”登録”></td>
</tr>
</table>
</form>
</body>
</html>
3.userReg.jsp
<%@ page language=”java” contentType=”text/html; charset=UTF-8″%>
<% request.setCharacterEncoding(“UTF-8″);
<jsp:UserBean id=”user” scope=”page” class=”com.ctn.kdf.UserBean”></jsp:UserBean>
<jsp:setProperty property=”*” name=”user” />
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>会員情報</title>
</head>
<body>
ユーザID:<jsp:getProperty property=”name” name=”user” />
</body>
</html>