测试jsp时出现java.lang.StringIndexOutOfBoundsException: String index out of range: 3
<%@pagelanguage="java"pageEncoding="gb2312"%><%@pageimport="java.sql.*"%><html><head>...
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>登陆判断页面
</title>
</head>
<body>
<%!String u=new String();%>
<%
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
try{
Class.forName(driverName);
Connection connection=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=HRMS","sa","123456");
Statement statement=connection.createStatement();
String k1=request.getParameter("uusername");
String k2=request.getParameter("upassword");
String selectSQL="select userlevel from KeyTable where username='"+k1+"' and password='"+k2+"'";
ResultSet result=statement.executeQuery(selectSQL);
int i=-1;
while(result.next())
{
i++;
u=result.getString("userlevel");
}
if(k1=="")
{
%><jsp:forward page="Win8_001.jsp"></jsp:forward><%
}
else if(k2=="")
{
%><jsp:forward page="Win8_001.jsp"></jsp:forward><%
}
else if(i==-1)
{
%><jsp:forward page="loginFailure.jsp"></jsp:forward><%
}
else if(i>=0)
{
if(u.equals("普通"))
{
%><jsp:forward page="loginSuccess.jsp"></jsp:forward><%
}
else if(u.equals("管理员"))
{
%><jsp:forward page="loginManagerSuccess.jsp"></jsp:forward><%
}
}
statement.close();
connection.close();
} catch (ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e){
e.printStackTrace();
}
%>
</body>
</html>
当level时“管理员”时是成功的。 展开
<%@ page import="java.sql.*"%>
<html>
<head>
<title>登陆判断页面
</title>
</head>
<body>
<%!String u=new String();%>
<%
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
try{
Class.forName(driverName);
Connection connection=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=HRMS","sa","123456");
Statement statement=connection.createStatement();
String k1=request.getParameter("uusername");
String k2=request.getParameter("upassword");
String selectSQL="select userlevel from KeyTable where username='"+k1+"' and password='"+k2+"'";
ResultSet result=statement.executeQuery(selectSQL);
int i=-1;
while(result.next())
{
i++;
u=result.getString("userlevel");
}
if(k1=="")
{
%><jsp:forward page="Win8_001.jsp"></jsp:forward><%
}
else if(k2=="")
{
%><jsp:forward page="Win8_001.jsp"></jsp:forward><%
}
else if(i==-1)
{
%><jsp:forward page="loginFailure.jsp"></jsp:forward><%
}
else if(i>=0)
{
if(u.equals("普通"))
{
%><jsp:forward page="loginSuccess.jsp"></jsp:forward><%
}
else if(u.equals("管理员"))
{
%><jsp:forward page="loginManagerSuccess.jsp"></jsp:forward><%
}
}
statement.close();
connection.close();
} catch (ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e){
e.printStackTrace();
}
%>
</body>
</html>
当level时“管理员”时是成功的。 展开
2013-07-16
展开全部
字符串类型的数组,超出范围
错误的不在上面,看后台的LOG,就知道具体的错误地方了
错误的不在上面,看后台的LOG,就知道具体的错误地方了
追问
怎么看后台的log
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-17
展开全部
修改后缀名试试看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询