当前位置:编程学习 > JAVA >>

jsp用账号密码表登录后获取信息表的值.晕。闹不出来啊。空值!!

users表里面有userno,usersname,userpwd,role,字段,其中userno为主键,students表里面有stuno(主键),其中还是一些乱七八糟的信息。学生登陆后如何获取相应stuno的信息?跪求代码啊
下面是登录页的代码

<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*" errorPage=""%>
<%@ page session="true" %>
<HTML>
<HEAD>
<TITLE>登录验证</TITLE>

</HEAD>
<BODY>
 <% 
String user = new String(((request.getParameter("username")).trim()).getBytes("ISO-8859-1"));
String pass = new String(((request.getParameter("password")).trim()).getBytes("ISO-8859-1"));
String type = new String(((request.getParameter("role")).trim()).getBytes("ISO-8859-1"));
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/ma?user=root&password=1234&useUnicode=true&characterEncoding=gb2312");
Statement stmt = con.createStatement();
String sql = "select role from users where username='" + user + "' and userpwd='" + pass + "' and role='" + type + "'";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){ 
  if(type.equals("1")){ 
   session.setAttribute("username",user);
                     session.setAttribute("role",type);
                     response.sendRedirect("student/student.html"); 
  }else if(type.equals("2")){ 
   session.setAttribute("username",user);
                     session.setAttribute("role",type);
                     response.sendRedirect("teacher/teacher.html");
 
  }else if(type.equals("0")){ 
   session.setAttribute("username",user);
                     session.setAttribute("role",type);
                     response.sendRedirect("admin/admin.html");
  } 
     }

else
{
%>

<style type="text/css">
<!--
body {
background-image: url();
}
#Layer1 {
position:absolute;
width:250px;
height:115px;
z-index:1;
left: 312px;
top: 298px;
}
.STYLE19 {font-size: 20px}
.STYLE20 { color: #000066;
font-weight: bold;
}
.STYLE6 {
font-size: 16px;
color: #663399;
}
.STYLE7 {color: #0033CC}
.STYLE12 {color: #FFFF99}
-->
</style>



<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>

<DIV align=center>
  </TD>
  <IMG 
      src="images/line.jpg" 
      width=757 height=5 border=0>
  <TD width=21><p> </p>
        <table width="317" height="183" border="2" align="center">
              <tr>
                <td height="175" bgcolor="#9999FF"><p align="center" class="STYLE19 STYLE20"><span class="STYLE12">用户名不存在或密码错误。</span></p>
                  <p align="center" class="STYLE20 STYLE6">请<a href="index.html">重新登录</a>!</p></td>
              </tr>
            </table>
        <p> </p>
          <p> </p></TD>
    <TD vAlign=top width=503>
      <TABLE id=table2 cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>          </TR></TBODY></TABLE>

</TD></TR>
  <TR>  
    <TD height=52></TD></TR>
  <TR>
    <TD colSpan=3><IMG height=5 
      src="file/line.jpg" 
      width=757 border=0></TD>
  </TR>
  <TR>
    <TD height=15></TD></TR>
  <TR>
    <TD colspan="3">
      <P align=right>                     </P></TD>
</TR></TBODY>
</TABLE>
</DIV>


<%
}

rs.close();
stmt.close();
con.close();
%>
</BODY>
</HTML>
--------------------编程问答-------------------- 哪里为空呀,
String user = new String(((request.getParameter("username")).trim()).getBytes("ISO-8859-1"));
String pass = new String(((request.getParameter("password")).trim()).getBytes("ISO-8859-1"));
String type = new String(((request.getParameter("role")).trim()).getBytes("ISO-8859-1"));

你这三个都有值不呀? --------------------编程问答-------------------- 首先,楼主贴代码的时候最好能选择菜单栏 第七个 按钮,选择“插入源代码”
其次,楼主是哪里没有得到值呢? 按位置输出一下,看看。 --------------------编程问答-------------------- 我想对楼主说的是,你的users表和students表的关联字段是什么,两个表没有联系怎么能取出信息呢 --------------------编程问答-------------------- --------------------编程问答-------------------- userName=new String(userName.getByte("ISO-8859-1"),"UTF-8") --------------------编程问答-------------------- 把出现问题的地方标出来 --------------------编程问答--------------------
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,