getBytes(";ISO-8859-1";),";utf-8“在JSP页面中不工作

getBytes(";ISO-8859-1";),";utf-8“在JSP页面中不工作,jsp,tomcat,Jsp,Tomcat,我正在为我的博客建立网站。当我测试其他语言的编码时 27 <% 28 String str = request.getParameter("stone"); 29 out.println(new String(str.getBytes("ISO-8859-1"), "utf-8")); 30 %> 27 我不知道这段代码为什么会出现以下错误: HTTP状态500-在第29行处理JSP页面/index.JSP时发生异常 我会将代码包装在try/catch结构中。因此

我正在为我的博客建立网站。当我测试其他语言的编码时

27   <%
28   String str = request.getParameter("stone");
29   out.println(new String(str.getBytes("ISO-8859-1"), "utf-8"));
30   %>
27
我不知道这段代码为什么会出现以下错误:

HTTP状态500-在第29行处理JSP页面/index.JSP时发生异常


我会将代码包装在try/catch结构中。因此,

String str;
try {
  str = request.getParameter("stone");
  out.println(new String(str.getBytes("ISO-8859-1"), "utf-8"));
} catch (Exception e) {
   out.print("<p>An unexpected exception occurred: " + e.getMessage() + "</p>");
}
String-str;
试一试{
str=request.getParameter(“stone”);
println(新字符串(str.getBytes(“ISO-8859-1”),“utf-8”);
}捕获(例外e){
out.print(“发生意外异常:”+e.getMessage()+“

”; }

希望有帮助

您确定
request.getParameter(“stone”)
没有返回null吗?我在try/catch中这样做了。但也发生了同样的错误。