|
我是用MyEclipse5.0+jboss4.0.3的工具,建了一个webProject,很简单,就是在input.html页面上填写表单,提交到input.jsp页面上,通过使用jsp中的
<jsp:useBean class="com.fzu.edu.Student" id="stu" scope="request"/>
<jsp:setProperty name="stu" property="*"/>
<jsp:forward page="display.jsp"/>
,然后在display.jsp中用一张表格把在input.html页面上内容显示出来,问题是如果在input.html页面中有中文,则在display.jsp中就显示一大堆?之类的乱码,请问怎么办?
各个页面的详细代码如下:
1、input.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>input.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<br><br>
<center>
<form action="Input.jsp">
<ul>
<li>姓名:<input name="name"><br><br>
<li>学号:<input name="id"><br><br>
<li>性别:<input name="sex"><br><br>
<li>年龄:<input name="age"><br><br>
</ul>
<input type="submit" value="提交">
<input type="reset" value="重填">
</form>
</center>
</body>
</html>
2、input.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>input page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<jsp:useBean class="com.fzu.edu.Student" id="stu" scope="request"/>
<!--
用property="*"自动匹配JavaBean中的所有属性值对
-->
<jsp:setProperty name="stu" property="*"/>
<jsp:forward page="display.jsp"/>
<body>
</body>
</html>
3、display.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:useBean class="com.fzu.edu.Student" id="stu" scope="request"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>display page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body><br><br>
<%
request.setCharacterEncoding("gb2312");
%>
<center>
<font size="+2">学生信息</font><br/><br/>
<table border="1">
<tr>
<td>姓名:</td><td><jsp:getProperty name="stu" property="name"/></td>
</tr>
<tr>
<td>学号:</td><td><jsp:getProperty name="stu" property="id"/></td>
</tr>
<tr>
<td>性别:</td><td><jsp:getProperty name="stu" property="sex"/></td>
</tr>
<tr>
<td>年龄:</td><td><jsp:getProperty name="stu" property="age"/></td>
</tr>
</table>
</center>
</body>
</html>
4、Student
package com.fzu.edu;
/**
* @author ZYM
*
*/
public class Student {
public Student(){
}
private String name;
private String id;
private String sex;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
} |
|