jsp乱码
jsp是一个比较容易出现乱码的web开发语言,在学习java的过程中,我遇到了这个问题,解决方法如下:
乱码分为两种
<1>页面显示乱码
<2>获取表单数据乱码
<1>的解决方法:1.页面以 UTF-8的方式存储 2.页面编码方式声明:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<2>的解决方法:
<form action="" method="get" >
输入一个值:
<input type="text" name="myInput" />
<input type="submit" value="提交" />
</form>
<%
String strValue = request.getParameter("myInput");
byte c[] = strValue.getBytes("ISO-8859-1");
strValue = new String(c,"UTF-8");
if(null != strValue)
{
out.print("the value you input is " + strValue);
}
%>
浙公网安备 33010602011771号