标题:在servlet中Hidden的value属性问题
取消只看楼主
tianbian210
Rank: 1
等 级:新手上路
帖 子:46
专家分:1
注 册:2008-12-25
结帖率:87.5%
 问题点数:0 回复次数:1 
在servlet中Hidden的value属性问题
//隐藏表单案例提交界面

package com.tk;

import javax.servlet.http.*;
import *;

public class HiddenForm1 extends HttpServlet{
    //处理get请求
    public void doGet(HttpServletRequest req,HttpServletResponse res){
        //业务逻辑
        try{
            //中文乱码
            res.setContentType("text/html;charset=gbk");
            
            PrintWriter pw=res.getWriter();
            
            //返回登陆界面
            pw.println("<html>");
            pw.println("<body>");
            pw.println("<h1>登陆界面</h1>");
            pw.println("<form action=HiddenForm2 method=post>");
            pw.println("用户名:<input type=text name=username><br>");
            pw.println("密码:<input type=password name=passwd><br>");
            pw.println("<input type=hidden name=id value=男><br>");
            pw.println("<input type=submit value=loing><br>");
            pw.println("</form>");
            pw.println("</body>");
            pw.println("</html>");
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
    }
    //处理Post请求
    public void doPost(HttpServletRequest req,HttpServletResponse res){
        this.doGet(req,res);
    }
}

package com.tk;
import javax.servlet.http.*;
import *;

public class HiddenForm2 extends HttpServlet{
    //处理get请求
    public void doGet(HttpServletRequest req,HttpServletResponse res){
        
        try{
            //中文乱码
            res.setContentType("text/html;charset=gbk");
            PrintWriter pw=res.getWriter();
            String u=req.getParameter("username");
            String p=req.getParameter("passwd");
            String i=req.getParameter("id");
            
            pw.println("username="+u);
            pw.println("passwd="+p);
            pw.println("id="+i);
        }
        catch(Exception ex){
            ex.printStackTrace();
        }   
    }
    //处理Post请求
    public void doPost(HttpServletRequest req,HttpServletResponse res){
        this.doGet(req,res);
    }
}
输出时“男”显示为“??”。请问是为什么啊?
搜索更多相关主题的帖子: 属性 servlet value Hidden 
2010-04-03 10:17
tianbian210
Rank: 1
等 级:新手上路
帖 子:46
专家分:1
注 册:2008-12-25
得分:0 
谢谢版主
2010-04-03 10:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-301505-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.272773 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved