在servlet中Hidden的value属性问题
//隐藏表单案例提交界面package com.tk;
import javax.servlet.http.*;
import java.io.*;
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 java.io.*;
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
----------------解决方案--------------------------------------------------------
处理中文乱码还要加多一句
request.setCharacterEncoding("GBK");
----------------解决方案--------------------------------------------------------
谢谢版主
----------------解决方案--------------------------------------------------------