利用javabean 的<jsp:getProperty>和<jsp:setProperty>,在表单中输入数字可以正常显示,但是输入汉字后,输出的为什么是"???"
javabean代码:
package yky;
import java.io.*;
public class SampleBean2
{
public SampleBean2()
{
}
private String id;
private String age;
public void setId(String id)
{
this.id = id;
}
public void setAge(String age)
{
this.age= age;
}
public String getId()
{
return id;
}
public String getAge()
{
return age;
}
}jsp代码:
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<jsp:useBean id="sqlBean" class="yky.SampleBean2"/>
<html>
<head>
<title>javaBean</title>
</head>
<body>
<jsp:setProperty name="sqlBean" property="*"/>
<center>
编号:<jsp:getProperty name="sqlBean" property="id"/><br>
年龄:<jsp:getProperty name="sqlBean" property="age"/><br>
</center>
</body>
</html>html代码:
<html>
<head>
<title>使用<jsp:getProperty>和<jsp:setProperty>标记</title>
</head>
<body>
<form name="form1" action="http://localhost:8080/ch1/sample2.jsp" method="post">
<p align="center">编号:
<input type="text" name="id">
</p>
<p align="center">年龄:
<input type="text" name="age">
</p>
<p align="center">
<input type="submit" value="提交">
<input type="reset" value="重填">
</p>
</form>
</body>
</html>
javabean代码:
package yky;
import java.io.*;
public class SampleBean2
{
public SampleBean2()
{
}
private String id;
private String age;
public void setId(String id)
{
this.id = id;
}
public void setAge(String age)
{
this.age= age;
}
public String getId()
{
return id;
}
public String getAge()
{
return age;
}
}jsp代码:
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<jsp:useBean id="sqlBean" class="yky.SampleBean2"/>
<html>
<head>
<title>javaBean</title>
</head>
<body>
<jsp:setProperty name="sqlBean" property="*"/>
<center>
编号:<jsp:getProperty name="sqlBean" property="id"/><br>
年龄:<jsp:getProperty name="sqlBean" property="age"/><br>
</center>
</body>
</html>html代码:
<html>
<head>
<title>使用<jsp:getProperty>和<jsp:setProperty>标记</title>
</head>
<body>
<form name="form1" action="http://localhost:8080/ch1/sample2.jsp" method="post">
<p align="center">编号:
<input type="text" name="id">
</p>
<p align="center">年龄:
<input type="text" name="age">
</p>
<p align="center">
<input type="submit" value="提交">
<input type="reset" value="重填">
</p>
</form>
</body>
</html>
看看
<% response.setCharacterEncoding("gb2312"); %>
加个函数来转换
public static String toChinese(String input) {
try {
byte[] bytes = input.getBytes("ISO8859-1");
return new String(bytes);
}
catch (Exception ex) {
}
return null;
}
在jsp页面中加这样一句,
<% response.setCharacterEncoding("gb2312"); %>
我给你补分。呵呵 谢谢