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>&nbsp;</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>&nbsp;</p>
          <p>&nbsp;</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>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;  </P></TD>
</TR></TBODY>
</TABLE>
</DIV>
<%
}rs.close();
stmt.close();
con.close();
%>
</BODY>
</HTML>

解决方案 »

  1.   

    哪里为空呀,
    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"));你这三个都有值不呀?
      

  2.   

    我想对楼主说的是,你的users表和students表的关联字段是什么,两个表没有联系怎么能取出信息呢
      

  3.   

    userName=new String(userName.getByte("ISO-8859-1"),"UTF-8")