*.jsp
<%=test.setTest()%>*.java
public void setTest(String newTest) {this.test = newTest;}
JSP提交页面到javaBean会出现汉字乱码怎么解决?
我不想用servlet
<%=test.setTest()%>*.java
public void setTest(String newTest) {this.test = newTest;}
JSP提交页面到javaBean会出现汉字乱码怎么解决?
我不想用servlet
<%=test.setTest("成功发表!")%> *.java
public void setTest(String newTest) {this.test = newTest;}
<%request.setCharactorEncoding("GBK"); %>
或者
<%request.setCharactorEncoding("UTF-8"); %>根据你采用的编码不同,记得是第二行
第一行一般是
<%@page contentType....
*.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="" method="post" name="form">
标题:<input type="text" name="title" value="">
内容:<input type="text" name="content" value="">
<input type="submit" value="送出" name=submit>
</form>
<jsp:useBean id="test" class="javaBean.test" scope="session"></jsp:useBean>
你输入的是:
<%
String title=request.getParameter("title");
String content=request.getParameter("content");
test.setTest(title,content);
%>
<%=test.getTest()%>
</body>
</html>
*.javaimport java.io.*;public class test implements java.io.Serializable {
String Test=""; public String getTest() {return Test;} public void setTest(String title,String content) { this.Test = "标题:"+title+"<br>内容:"+content;
}
}
<%request.setCharactorEncoding("UTF-8"); %>
传送数据之前将编码更改过来
<%request.setCharacterEncoding("utf-8");%>
我以前试着在*.java里加这个
结果怎么也加不上,原来在这里加
<% request.setCharactorEncoding("GBK");%>
都可以解决中文乱麻的问题么
<%request.setCharactorEncoding("UTF-8");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="" method="post" name="form">
标题: <input type="text" name="title" value="">
内容: <input type="text" name="content" value="">
<input type="submit" value="送出" name=submit>
</form>
<jsp:useBean id="test" class="javaBean.test" scope="session"> </jsp:useBean>
你输入的是:
<% ]
String title=request.getParameter("title");
String content=request.getParameter("content");
test.setTest(title,content);
%>
<%=test.getTest()%>
</body>
</html>
*.java import java.io.*; public class test implements java.io.Serializable {
String Test=""; public String getTest() {return Test;} public void setTest(String title,String content) { this.Test = "标题:"+title+" <br> 内容:"+content;
}
}
另外,中文乱码网上应该会有一筐好用的方法
在页头上加上这句:
<%@page contentType="text/html;charset=GB2312"%>
在jsp页面上加入这条语句:
<% request.setCharacterEncoding("gb2312"); %>
=================================================
或者
response.setContentType("text/html;charset=GB2312");
request.setCharacterEncoding("gb2312");
str=new String(request.getParmaeter("str").getBytes("ISO-8859_1"),"GB2312");