日期:2014-05-17  浏览次数:20854 次

大家帮忙看下为什么 u 的值是个乱码啊??
public class LoginCL extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

this.doPost(request, response);
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
  String u=request.getParameter("username");
  System.out.println(u);
  String p=request.getParameter("passwd");
  Connection ct=null;
  PreparedStatement ps=null;
  ResultSet rs=null;
  try {
Class.forName("oracle.jdbc.driver.OracleDriver");
try {
ct=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcllib","scott","yh123456");

 
//使用preparestatement对象执行sql语句
ps=ct.prepareStatement("select upasswd from user1 where uname=?");
System.out.println(u);
//写入参数 
ps.setString(1,u);
rs=ps.executeQuery();
System.out.println(rs);
if (rs.next()) {
//合法
System.out.println("abcdefg");
//获得session
HttpSession hs=request.getSession(true);
//修改session时间 秒
hs.setMaxInactiveInterval(20);
//写入session
hs.setAttribute("pass", "ok");

response.sendRedirect("Wel?uname="+u+"&upass="+p);

} else {
//不合法
System.out.println("hello");
response.sendRedirect("Login");

}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(rs!=null){
rs.close();
}
if(rs!=null){
ps.close();
}
if(rs!=null){
ct.close();
}

} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
}
   

}

}


------解决方案--------------------
探讨

多谢各位大侠指导!我刚开始学servlet不是很懂请大家多多包涵!!我还是再贴一段代码吧
这是上面那段代码(LoginCL)的上一个一页面
public class Login extends HttpServlet {



public void doGet(HttpServletRequest request, HttpServletResponse response)
th……