回 帖 发 新 帖 刷新版面

主题:错误在哪

login.java
package bookshop.run;
/**
 * <p>管理用户登录的类 </p>
 */
import bookshop.util.*;
public class login extends DataBase {
        private String username;    //登录用户名
        private String passwd;        //登录密码
        private boolean isadmin;    //是否管理员登录
        private long userid=0;        //用户ID号
        public login() throws Exception{
                super();
                username = "";
                passwd = "";
                isadmin = false;
        }
        public String getUsername() {
                return username;
        }
        public void setUsername(String newusername) {
                username = newusername;
        }
        public String getPasswd() {
                return passwd;
        }
        public void setPasswd(String newpasswd) {
                passwd = newpasswd;
        }
        public boolean getIsadmin() {
                return isadmin;
        }
        public void setIsadmin(boolean newIsadmin) {
                isadmin = newIsadmin;
        }
        public long getUserid() {
                return userid;
        }
        public void setUserid (long uid) {
                userid = uid;
        }
        /**
         * 获得查询用户信息的sql语句
         * @return
         */
        public String getSql() {
                if (isadmin) {
                        sqlStr = "select * from bookadmin where adminuser = '" +
                            dataFormat.toSql(username) + "' and adminpass = '" +
                            dataFormat.toSql(passwd) + "'";
                }else {
                        sqlStr = "select * from shop_user where username = '" +
                            username + "' and password = '" + passwd + "'";
                }
                return sqlStr;
        }
        /**
         * 执行查询
         * @return
         * @throws java.lang.Exception
         */
        public boolean excute() throws Exception {
                boolean flag = false;
                DataBase db = new DataBase();
                db.connect();
                stmt = db.conn.createStatement ();
                rs = stmt.executeQuery(getSql());
                if (rs.next()){
                        if (!isadmin)
                        {
                                userid = rs.getLong("id");
                        }
                        flag = true;
                }
                rs.close();
                return flag;
        }
};


回复列表 (共1个回复)

沙发

<%@ page session="true" %>
<jsp:useBean id="login" scope="page" class="bookshop.run.login" />
<%
String mesg = "";

if( request.getParameter("username")!=null && !request.getParameter("username").equals("")){
    String username =request.getParameter("username");
    String passwd = request.getParameter("passwd");
    username = new String(username.getBytes("ISO8859-1"));
    passwd = new String(passwd.getBytes("ISO8859-1"));
    login.setUsername(username);
    login.setPasswd(passwd);
    out.print(username+passwd);
    if (login.excute()){
        session.setAttribute("username",username);
        String userid = Long.toString(login.getUserid());
        session.setAttribute("userid",userid);
        response.sendRedirect("booklist.jsp");
        %>
<%    
    }else {
    mesg = "登录出错!"    ;
    }
}
%>
<%@include file="/bookshop/inc/head.inc"%>

<script language="javascript">

 function checkform() {
    if (document.form1.username.value=="" || document.form1.passwd.value==""){
        alert("用户名或密码为空!");
        return false;
    }
    return true;

  }

</script>
<div align=center>用户登录 </div>
          <br>          
<% if (!mesg.equals("")){
                        out.println("<p>" + mesg + "</p>");}%>
                        
  <form name="form1" method="post" action="login.jsp">
    <table width="400" border="0" cellspacing="1" cellpadding="1" align="center">
    <tr> 
      <td width="147" align="right">用户名:<br>
      </td>
      <td width="246" valign="top">
          <input type="text" name="username" size="16" maxlength="25">
        </td>
    </tr>
    <tr> 
      <td width="147" align="right">密码:</td>
      <td width="246" valign="top">
          <input type="password" name="passwd" maxlength="20" size="16">
        </td>
    </tr>
    <tr> 
      <td width="147" align="right">&nbsp;</td>
      <td width="246" valign="top">
          <input type="submit" name="Submit" value="登录" onclick="javascript:return(checkform());">
          <input type="reset" name="Submit2" value="取消">
        </td>
    </tr>
    <tr>     
      <td colspan="2" align="center">
        <p>&nbsp;</p>
        测试用户:wxy 密码:wxy
      </td>
    </tr>
    <tr> 
    
      <td colspan="2" align="center">
        <p>&nbsp;</p>
        <p>如果你还不是本站用户,请在此<a href="reg.jsp">注册</a></p>
      </td>
    </tr>
  </table>
    </form>
 <%@include file="/bookshop/inc/tail.inc"%>

错误提示:

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 3 in the jsp file: /bookshop/login.jsp

Generated servlet error:
    [javac] Compiling 1 source file

C:\Tomcat5.0\work\Catalina\localhost\_\org\apache\jsp\bookshop\login_jsp.java:48: package bookshop.run does not exist
      bookshop.run.login login = null;
                  ^



An error occurred at line: 3 in the jsp file: /bookshop/login.jsp

Generated servlet error:
C:\Tomcat5.0\work\Catalina\localhost\_\org\apache\jsp\bookshop\login_jsp.java:50: package bookshop.run does not exist
        login = (bookshop.run.login) pageContext.getAttribute("login", PageContext.PAGE_SCOPE);
                             ^



An error occurred at line: 3 in the jsp file: /bookshop/login.jsp

Generated servlet error:
C:\Tomcat5.0\work\Catalina\localhost\_\org\apache\jsp\bookshop\login_jsp.java:53: package bookshop.run does not exist
            login = (bookshop.run.login) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "bookshop.run.login");
                                 ^
3 errors


    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
    org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.12

我来回复

您尚未登录,请登录后再回复。点此登录或注册