这个登陆界面我为什么运行不出来?
我把编译后的*.class文件加在了tomcat下的classes(我新建的)
为什么还是不能运行?到底还有什么问题呢?
登录页面使用的beans Login.java: package tom.jiafei; import java.sql.*; public class Login { String logname, password, success="false", message=""; //用来返回登录是否成功的消息。 Connection con; Statement sql; ResultSet rs; public Login() { //加载桥接器: try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException e){} } //设置属性值、获取属性值的方法: public void setLogname(String name) { logname=name; } public String getLogname() {return logname; } public void setPassword(String pw) { password=pw; } public String getPassword() {return password; } public String getSuccess() {return success; } //查询数据库的member表: public String getMessage() {try{ con=DriverManager.getConnection("jdbc:odbc:friend","",""); sql=con.createStatement(); String condition= "SELECT * FROM member WHERE logname = "+"'"+logname+"'"; rs=sql.executeQuery(condition); int rowcount=0; String ps=null; while(rs.next()) { rowcount++; logname=rs.getString("logname"); ps=rs.getString("password"); } if((rowcount==1)&&(password.equals(ps))) { message="ok"; success="ok"; } else {message="输入的用户名或密码不正确"; success="false"; } con.close(); return message; } catch(SQLException e) { message="输入的用户名或密码不正确"; success="false"; return message; } } }
会员登录页面
login.jsp: <%@ page contentType="text/html;charset=GB2312" %> <%@ page import="tom.jiafei.Login" %> <%! //处理字符串的方法: public String codeString(String s) { String str=s; try{byte b[]=str.getBytes("ISO-8859-1"); str=new String(b); return str; } catch(Exception e) { return str; } } %> <HTML> <BODY bgcolor=cyan ><Font size=1> <%@ include file="head.txt" %> <Font size=1> <P>输入用户名和密码: <%String str=response.encodeURL("login.jsp"); %> <FORM action="<%=str%>" Method="post"> <BR>登录名称<Input type=text name="logname"> <BR>输入密码<Input type=password name="password"> <BR><Input type=submit name="g" value="提交"> </Form> <jsp:useBean id="login" class="tom.jiafei.Login" scope="session" > </jsp:useBean> <% //提交信息后,验证信息是否正确: String message="", logname="", password=""; if(!(session.isNew())) {logname=request.getParameter("logname"); if(logname==null) {logname=""; } logname=codeString(logname); password=request.getParameter("password"); if(password==null) {password=""; } password=codeString(password); } %> <% if(!(logname.equals(""))) { %> <jsp:setProperty name= "login" property="logname" value="<%=logname%>" /> <jsp:setProperty name= "login" property="password" value="<%=password%>" /> <% message=login.getMessage(); //获取返回的验证信息。 if(message==null) {message=""; } } %> <% if(!(session.isNew())) { if(message.equals("ok")) {String meb=response.encodeURL("showMember.jsp"); response.sendRedirect(meb); } else {out.print(message); } } %> </Body> </HTML>