日期:2014-05-16  浏览次数:20345 次

jsp中文乱码解决方案.

?

<!--[if !supportLists]-->1.?????? <!--[endif]-->表单提交中文

?------login.jsp--------?

? 下面是表单内容:

? <form action="AcceptFormCharset.jsp" method="post">

?????? 用户名:<input type="text" name="userName" size="10"/>

?????? ? 码:<input type="password" name="password" size="10"/>

????? <input type="submit" value="提交">

?? </form>?

? ??

-----------AcceptFormCharset.jsp---------

? <body>

? <font size="2">

?? 下面是表单提交以后用request取到的表单数据:<br>

?? <%

????? String userName = request.getParameter("userName");

????? String password = request.getParameter("password");

? ? ? out.println("表单输入userName的值:"+new String(userName.getBytes("ISO-8859-1"),"gb2312")+"<br>");

????? out.println("表单输入password的值:"+new String(password.getBytes("ISO-8859-1"),"gb2312")+"<br>");

? ? 这里所提交的值如果是中文的话,直接用输出就会出现乱码,因为java默认的是用unicode编码,这里采取的方 ? ? 法是将值从ISO-8859-1中提取出来转化为gb2312的编码方式就可以显示出中文

??? %>

?? </font>

? </body>

2.URL提交表单的值?

? <%

?????? String param = request.getParameter("param");

?? %>

? <body>

??<a href="hehe.jsp?param='中文'">请点击这个链接</a><br&