问题描述
代码如下:<%@pagecontentType="text/html;charset=GB2312"%><%@pageimport="java.sql.*"%><html><head><title>图书馆管理系统</title></head><body><scriptlanguage="javaScript">functionvalidate(f){if(!(/^w{5,15}$/.test(f.userid.value))){alert("用户ID必须是5~15位!");f.userid.focus();returnfalse;}if(!(/^w{5,15}$/.test(f.password.value))){alert("密码必须是5~15位!");f.password.focus();returnfalse;}returntrue;}</script><formaction="check.jsp"method="post"onSubmit="returnvalidate(this)"><tableborder="0"><tr><tdcolspan="2">用户登陆程序</td></tr><tr><td>用户ID:</td><td><inputtype="text"name="userid"></td></tr><tr><td>密 码:</td><td><inputtype="password"name="password"></td></tr><tr><tdcolspan="2"><inputtype="submit"value="登陆"><inputtype="reset"value="重置"></td></tr></table></form></body></html><%!publicstaticfinalStringDBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";publicstaticfinalStringDBURL="jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=Libary";publicstaticfinalStringDBUSER="sa";publicstaticfinalStringDBPASS="123";%><%Connectionconn=null;PreparedStatementpstmt=null;ResultSetrs=null;booleanflag=false;%><%Stringuserid=request.getParameter("userid");Stringpassword=request.getParameter("password");try{Class.forName(DBDRIVER);conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);Stringsql="SELECTuserid,passwordFROMtuserWHEREuserid=?ANDpassword=?";pstmt=conn.prepareStatement(sql);pstmt.setString(1,userid);pstmt.setString(2,password);rs=pstmt.executeQuery();if(rs.next()){flag=true;}}catch(Exceptione){}finally{try{conn.close();}catch(Exceptione){}}%><%if(flag){%><jsp:forwardpage="booklend.jsp"/><%}else{%><jsp:forwardpage="failure.jsp"/><%}%>
解决方案
解决方案二:
/Management/failure.jsp錯誤碼404所以你所貼的代碼應該在/Management目錄,但failure.jsp卻不在那個目錄。調整到對的目錄就可以了例如在上一層就用<jsp:forwardpage="../failure.jsp"/>再上一層的comm目錄就用<jsp:forwardpage="../comm/failure.jsp"/>
解决方案三:
你这个问题我以前遇到过,你是不是有个**.java的文件啊,里面publicResultSetexecuteQuery(Stringsql){rs=null;try{if(conn==null){conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);}stmt=conn.createStatement();rs=stmt.executeQuery(sql);这段的倒数第二句本来是因该在花括号里面的,但是在里面就会出现错误,所以我写到外面来就对了。我以前是用alert一句句查出来的