日期:2014-05-18  浏览次数:20802 次

jsp跨页面值传输请求帮助
我想把登陆的用户名从第一个页面传送到第三个页面.用session实现.
第一个页面的相关代码
<%   String   username=request.getParameter( "username ");
String   pwd=request.getParameter( "pwd ");
ResultSet   rs=null;
String   sql= "select   *   from   userinfo   where   username= ' "+username+ " '   and   pwd= ' "+pwd+ " ' ";
rs=user.executeQuery(sql);
session.setAttribute( "username ",rs.getString( "username ");
if(rs.next())
{out.print( "ok ");
  response.sendRedirect( "main.jsp ");
  );
  }
else
{   String   msg= "用户或密码错误 ";
    out.println(msg);
    response.sendRedirect( "index.jsp ");
}
rs.close();
%>
第三个页面的相关代码
<%   String     mn=session.getAttribute( "username ");
      ResultSet   rs=null;
      String   sql= "select   mnum   from   userinfo   where   username= ' "+mn+ " ' ";
      rs=adnum.executeQuery(sql);
      if(rs.next())
      {     String   adnu=(String)rs.getString( "adnum ");
            if(adnu== "1 ")
          {response.sendRedirect( "guanl.jsp ");
            }    
}
else{  
String   msg= "你没有管理员权限 ";
out.print(msg);
response.sendRedirect( "../main.jsp ");
}
rs.close();
%>
错误是:
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP:  

An   error   occurred   at   line:   9   in   the   jsp   file:   /biyesheji/adnumcheck.jsp
Type   mismatch:   cannot   convert   from   Object   to   String
6:   <title> adnumcheck </title>
7:   <jsp:useBean   class= "sqldb.MyDbBean "   id= "adnum "   scope= "page "> </jsp:useBean>
8:   </head>
9:   <%   String     mn=session.getAttribute( "username ");
10:         ResultSet   rs=null;
11:         String   sql= "select   mnum   from   userinfo   where   username= ' "+mn+ " ' ";
12:         rs=adnum.executeQuery(sql);

求助各位高手


------解决方案--------------------
<% String mn=session.getAttribute( "username ");
这句,改为 <% String mn=(String)session.getAttribute( "username ");试一下。
------解决方案--------------------

------解决方案--------------------
改成 String adnu=rs.getString( "mnum ");
------解决方案--------------------
getString返回的就是String,还转型干吗?而且比较adnu字符串为1不能用==而要用 "1 ".equals(adnu)的说,没看过基础语法知识啊?
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html