知道美河 | 上传资料 | VIP申请 | 精品课程 | 资料搜索 | 问题反馈 | 会员手册 | 积分消费 | 积分充值 | 帐号保护
美河学习学习在线赞助VIP

美河学习在线(主站) eimhe.com

 找回密码
 建立账号
查看: 7746|回复: 5

[求助] 高手请进,帮我解决个中文无法显示问题

[复制链接]
发表于 2007-3-28 20:33:11 | 显示全部楼层 |阅读模式

我是用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;
        }
       
}
发表于 2007-3-28 23:15:13 | 显示全部楼层
 楼主| 发表于 2007-3-29 13:13:07 | 显示全部楼层
除了加过滤还有其它解决办法吗?用include不用加过滤,只是把pageEncoding="gb2312" 改成
contentType="text/html;charset="gb2312""就可以了,为什么啊?
发表于 2007-3-29 15:35:20 | 显示全部楼层
contentType="text/html;charset="gb2312""  是用来显示中文的编码
 楼主| 发表于 2007-3-30 17:39:15 | 显示全部楼层
contentType="text/html;charset="gb2312"这个试过了,没用啊~~~~~
发表于 2007-4-1 13:44:02 | 显示全部楼层
原帖由 zym83215 于 2007-3-30 17:39 发表
contentType="text/html;charset="gb2312"这个试过了,没用啊~~~~~


那就试试contentType="text/html;charset=gbk"
您需要登录后才可以回帖 登录 | 建立账号

本版积分规则

 
QQ在线咨询

QQ|小黑屋|手机版|Archiver|美河学习在线 ( 浙网备33020302000026号 )

GMT+8, 2025-5-7 15:40

Powered by Discuz!

© 2001-2025 eimhe.com.

快速回复 返回顶部 返回列表