2013年9月20日星期五

jsp garbled

Intent: Step by Step Registration

concerns: first page to the first two pages , the first two pages of the first page of the information received in Chinese are garbled


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'testVoteAdd.jsp' starting page</title>
</head>

<body>
<form action="testVoteAdd2.jsp" method="post">
voteName:<input type="text" name="voteName" /><br>
voteType:<input type="radio" name="voteType" value="1"/>单选&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="voteType" value="2"/>多选<br>
voteOptionNum:<input type="text" name="voteOptionNum" /><br>
<input type="submit" value="Submit">
</form>
</body>
</html>



<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String voteName = request.getParameter("voteName");
String voteType = request.getParameter("voteType");
int voteOptionNum = Integer.parseInt(request.getParameter("voteOptionNum"));
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'testVoteAdd2.jsp' starting page</title>
</head>

<body>
<form action="TestVoteAddServlet" method="post">
<input type="hidden" name="voteName" value="<%=voteName%>" />
<input type="hidden" name="voteType" value="<%=voteType%>" />
<input type="hidden" name="voteOptionNum"
value="<%=String.valueOf(voteOptionNum)%>" />

<table width="80%" border="1" cellpadding="5">
<tr>
<th colspan="2"><%=voteName%></th>
</tr>
<%for (int i = 0; i < voteOptionNum; i++){%>
<tr><td>选项<%=i + 1%></td><td><input type="text" name="voteOption<%=i%>" /></td></tr>
<%}%>
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>



split into two pages , too, as above.

project UTF-8 encoding




JavaWeb started learning phase , the next chapter stresses javabean
------ Solution -------------------------- ------------------
pageEncoding page information is encoded , while setCharactrEncoding is encoded parameters between pages .
------ Solution ---------------------------------------- ----
pageEncoding settings argument does not work . Different browsers sends the information to the server using a different encoding , indexed to set request.setCharacterEncoding.
------ Solution ---------------------------------------- ----
page data sent is the character , you need to specify the character set
------ Solution --------------------- -----------------------
pageEncoding equivalent to just page encoding format, and setCharacterEncoding refers argument encoding
----- - Solution --------------------------------------------
Floor already said
------ Solution ------------------------------------ --------
in response to another page when it is coupled with UTF-8 encoding , and sometimes not with gb2312 utf8 can solve distortion ,
------ Solution --------------------------------------------
request.setCharacterEncoding ("UTF-8"); setting the request object passed parameters.
String voteName = request.getParameter ("voteName");
String voteType = request.getParameter ("voteType");
int voteOptionNum = Integer.parseInt (request.getParameter ("voteOptionNum")); these few lines to get parameters from the request . Set the encoding type will not be garbled
------ Solution ------------------------------- -------------
pageEncoding and request.setCharactrEncoding
------ Solution ------------------- -------------------------
request.setCharacterEncoding ("UTF-8"); setting the request object passed parameters.
then write data to be received there will be garbled
------ For reference only --------------------- ------------------
request.setCharacterEncoding ("UTF-8");

can be displayed properly , but do not understand why pageEncoding = "UTF-8" can not afford to effect ?

in other words, the request object data storage format is not UTF-8?
------ For reference only -------------------------------------- -
page data sent is the character , you need to specify the character set

pageEncoding page information is encoded , while setCharactrEncoding is encoded parameters between pages .

Thank you, understand, equivalent character stream

没有评论:

发表评论